summaryrefslogtreecommitdiff
path: root/src/unitparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unitparser.cpp')
-rw-r--r--src/unitparser.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/unitparser.cpp b/src/unitparser.cpp
new file mode 100644
index 0000000..891f7b3
--- /dev/null
+++ b/src/unitparser.cpp
@@ -0,0 +1,39 @@
1#include "unitparser.h"
2#include "parser.h"
3#include "lexer.h"
4
5#include <bu/sio.h>
6#include <bu/streamstack.h>
7#include <bu/membuf.h>
8
9UnitParser::UnitParser()
10{
11 setName("Parser");
12 add( static_cast<Bu::UnitSuite::Test>(&UnitParser::order1),
13 "order1", Bu::UnitSuite::expectPass );
14}
15
16UnitParser::~UnitParser()
17{
18}
19
20Bu::String parse( const Bu::String sEq, int iScale=0, int iRadix=10 )
21{
22 Bu::MemBuf mbIn( sEq );
23 Bu::MemBuf mbOut;
24 Lexer lex( mbIn );
25 lex.setScale( 5 );
26 Parser parser( lex, mbOut );
27 parser.parse();
28 return mbOut.getString().trimWhitespace();
29}
30
31void UnitParser::order1()
32{
33 unitTest(parse("2+3*5") == "17");
34 unitTest(parse("2+3-5") == "0");
35 unitTest(parse("(2+3)*5") == "25");
36 unitTest(parse("1.59*40/24*21", 5) == "55.125");
37 unitTest(parse("1.59*40/(24*21)", 5) == "0.125"); // bc says it's this: "0.12619");
38}
39