1 #include "UserTestTraits.hpp"
2 #include "t039labelsLexer.hpp"
3 #include "t039labelsParser.hpp"
4
5 #include <sys/types.h>
6
7 #include <iostream>
8 #include <sstream>
9 #include <fstream>
10
11 using namespace Antlr3Test;
12 using namespace std;
13
14 int testValid(string const& data);
15 int testMalformedInput(string const& data);
16
17 static t039labelsLexer *lxr;
18
19
20 struct TokenData
21 {
22 //t039labelsLexerTokens::Tokens type;
23 //unsigned start;
24 //unsigned stop;
25 const char* text;
26 };
27
28 static TokenData ExpectedTokens[] =
29 {
30 /*
31 lexer = self.getLexer(cStream)
32 tStream = antlr3.CommonTokenStream(lexer)
33 parser = self.getParser(tStream)
34 ids, w = parser.a()
35
36 self.assertEqual(len(ids), 6, ids)
37 self.assertEqual(ids[0].text, 'a', ids[0])
38 self.assertEqual(ids[1].text, 'b', ids[1])
39 self.assertEqual(ids[2].text, 'c', ids[2])
40 self.assertEqual(ids[3].text, '1', ids[3])
41 self.assertEqual(ids[4].text, '2', ids[4])
42 self.assertEqual(ids[5].text, 'A', ids[5])
43
44 self.assertEqual(w.text, 'GNU1', w)
45 */
46 // "a, b, c, 1, 2 A FOOBAR GNU1 A BLARZ"
47 { "a"},
48 { "b"},
49 { "c"},
50 { "1"},
51 { "2"},
52 { "A"},
53 };
54
55
main(int argc,char * argv[])56 int main (int argc, char *argv[])
57 {
58 testValid("a, b, c, 1, 2 A FOOBAR GNU1 A BLARZ");
59 return 0;
60 }
61
testValid(string const & data)62 int testValid(string const& data)
63 {
64 t039labelsLexerTraits::InputStreamType* input = new t039labelsLexerTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(),
65 ANTLR_ENC_8BIT,
66 data.length(), //strlen(data.c_str()),
67 (ANTLR_UINT8*)"t039");
68 if (lxr == NULL)
69 lxr = new t039labelsLexer(input);
70 else
71 lxr->setCharStream(input);
72
73 std::cout << "testValid: \"" << data << '"' <<std::endl;
74
75 t039labelsLexerTraits::TokenStreamType *tstream = new t039labelsLexerTraits::TokenStreamType(ANTLR_SIZE_HINT, lxr->get_tokSource());
76 t039labelsParser *psr = new t039labelsParser(tstream);
77 t039labelsParser::TokenList r = psr->a();
78
79 for(unsigned i = 0; i < r.tokens.size() ; i++)
80 {
81 t039labelsLexerTraits::CommonTokenType *token = r.tokens.at(i);
82
83 size_t startIndex = ((const char*)token->get_startIndex()) - data.c_str();
84 size_t stopIndex = ((const char*)token->get_stopIndex()) - data.c_str();
85
86 std::cout << token->getText()
87 << '\t' << (token->getText() == ExpectedTokens[i].text ? "OK" : "Fail")
88 << std::endl;
89
90 }
91 delete lxr; lxr = NULL;
92 delete input;
93 return 0;
94 }
95
96 /*
97 def testValid1(self):
98 cStream = antlr3.StringStream(
99 'a, b, c, 1, 2 A FOOBAR GNU1 A BLARZ'
100 )
101
102 lexer = self.getLexer(cStream)
103 tStream = antlr3.CommonTokenStream(lexer)
104 parser = self.getParser(tStream)
105 ids, w = parser.a()
106
107 self.assertEqual(len(ids), 6, ids)
108 self.assertEqual(ids[0].text, 'a', ids[0])
109 self.assertEqual(ids[1].text, 'b', ids[1])
110 self.assertEqual(ids[2].text, 'c', ids[2])
111 self.assertEqual(ids[3].text, '1', ids[3])
112 self.assertEqual(ids[4].text, '2', ids[4])
113 self.assertEqual(ids[5].text, 'A', ids[5])
114
115 self.assertEqual(w.text, 'GNU1', w)
116
117
118 if __name__ == '__main__':
119 unittest.main()
120
121
122 */
123