diff options
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 | ||