summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Tests/TestLexer.cpp
blob: 1000652c3c1309b771b1de9dcd0e115f29664c2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * TestLexer.cpp
 *
 *  Created on: Nov 4, 2012
 *      Author: attero
 */

#include "TestLexer.h"


TestLexer::TestLexer() {
	//Do nothing

}

TestLexer::~TestLexer() {
	// Do nothing
}

std::string TestLexer::all_tests()
{
	std::string test_report = "";

	mu_run_test(test_searching_keyword_for_not_keyword);
	mu_run_test(test_fake);
	mu_run_test(test_searching_keyword);
	mu_run_test(test_parsing_simple_token);
	mu_run_test(test_parsing_tricky_token);

	return test_report;
}

std::string TestLexer::test_fake()
{
	mu_assert("1 == 1", 1 == 1);
	return "";
}

std::string TestLexer::test_searching_keyword_for_not_keyword()
{
	mu_assert("Balloon is treated as a keyword.", !lexer.is_keyword("Balloon"));
	return "";
}

std::string TestLexer::test_searching_keyword()
{
	mu_assert("\"while\" isn't treated as keyword.", lexer.is_keyword("while"));
	return "";
}

std::string TestLexer::test_parsing_simple_token()
{
	std::string test_report = "";
	Token token = lexer.parse_token("buttocks^^").second;
	muu_assert(" buttocks isn't symbol token", token.type == t_symbol);
	muu_assert(" value isn't buttocks", token.value == "buttocks");
	return test_report;
}

std::string TestLexer::test_parsing_tricky_token()
{
	std::string test_report = "";
	Token token = lexer.parse_token("while_trhe#").second;
	muu_assert("while_trhe# not a symbol", token.type == t_symbol);
	muu_assert("value isn't while_trhe", token.value == "while_trhe");

	token = lexer.parse_token("1if").second;
	std::string rest_of_string = lexer.parse_token("1if").first;

	muu_assert("Isn\'t a number", token.type == t_invalid_token);
	muu_assert("Isn\'t equal 1if but ", token.value == "1if");
	muu_assert("Rest of string is crap", rest_of_string == "" );

	return test_report;
}