diff options
| author | Mike Buland <mike@xagasoft.com> | 2014-11-24 15:51:08 -0700 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2014-11-24 15:51:08 -0700 |
| commit | 3320e1496b1d099f63dea869f4a1cc19630dc3a9 (patch) | |
| tree | c56f8262951481376122650e9bc1c49358e304f1 /src/unitparser.cpp | |
| parent | f2f92156531b49da71067336ef0724f411226644 (diff) | |
| download | clic-3320e1496b1d099f63dea869f4a1cc19630dc3a9.tar.gz clic-3320e1496b1d099f63dea869f4a1cc19630dc3a9.tar.bz2 clic-3320e1496b1d099f63dea869f4a1cc19630dc3a9.tar.xz clic-3320e1496b1d099f63dea869f4a1cc19630dc3a9.zip | |
Fixed an annoying parsing bug.0.10
Diffstat (limited to 'src/unitparser.cpp')
| -rw-r--r-- | src/unitparser.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/unitparser.cpp b/src/unitparser.cpp index 43dacfc..6a5dcf4 100644 --- a/src/unitparser.cpp +++ b/src/unitparser.cpp | |||
| @@ -11,6 +11,8 @@ UnitParser::UnitParser() | |||
| 11 | setName("Parser"); | 11 | setName("Parser"); |
| 12 | add( static_cast<Bu::UnitSuite::Test>(&UnitParser::order1), | 12 | add( static_cast<Bu::UnitSuite::Test>(&UnitParser::order1), |
| 13 | "order1", Bu::UnitSuite::expectPass ); | 13 | "order1", Bu::UnitSuite::expectPass ); |
| 14 | add( static_cast<Bu::UnitSuite::Test>(&UnitParser::assignment), | ||
| 15 | "assignment", Bu::UnitSuite::expectPass ); | ||
| 14 | } | 16 | } |
| 15 | 17 | ||
| 16 | UnitParser::~UnitParser() | 18 | UnitParser::~UnitParser() |
| @@ -35,5 +37,19 @@ void UnitParser::order1() | |||
| 35 | unitTest(parse("(2+3)*5") == "25"); | 37 | unitTest(parse("(2+3)*5") == "25"); |
| 36 | unitTest(parse("1.59*40/24*21", 5) == "55.65"); | 38 | unitTest(parse("1.59*40/24*21", 5) == "55.65"); |
| 37 | unitTest(parse("1.59*40/(24*21)", 5) == "0.12619"); // bc says it's this: "0.12619"); | 39 | unitTest(parse("1.59*40/(24*21)", 5) == "0.12619"); // bc says it's this: "0.12619"); |
| 40 | unitTest(parse("10+2*2*2+2") == "20"); | ||
| 41 | } | ||
| 42 | |||
| 43 | void UnitParser::assignment() | ||
| 44 | { | ||
| 45 | Bu::MemBuf mbIn("$test = 2*2*2"); | ||
| 46 | Bu::MemBuf mbOut; | ||
| 47 | Lexer lex( mbIn ); | ||
| 48 | lex.setScale( 0 ); | ||
| 49 | Parser parser( lex, mbOut ); | ||
| 50 | parser.parse(); | ||
| 51 | Bu::println("%1 == %2").arg( mbOut.getString().trimWhitespace() ) | ||
| 52 | .arg( parser.getVariable("test") ); | ||
| 53 | unitTest( mbOut.getString().trimWhitespace() == parser.getVariable("test").toString() ); | ||
| 38 | } | 54 | } |
| 39 | 55 | ||
