Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 69 lines (53 sloc) 1.253 kB
e0a668e @txus Get ready for rbx
authored
1 # require 'rubygems'
2 # gem 'minitest'
3 # require 'minitest/unit'
f4f7a3c @txus add lexer tests
authored
4 require 'minitest/autorun'
e0a668e @txus Get ready for rbx
authored
5 # require 'minitest/spec'
fff47d0 @txus start working with rbx
authored
6 # require 'purdytest'
f4f7a3c @txus add lexer tests
authored
7
8bb73ff @txus Move stuff to stages.rb and leave compiler.rb for the bytecode compiler
authored
8 $: << 'lib'
f4f7a3c @txus add lexer tests
authored
9 require 'noscript'
10
11 class MiniTest::Unit::TestCase
fe8075c @txus assignment parser tests
authored
12
debaf37 @txus save a lot of bytes by using implicit namespaces in tests
authored
13 include Noscript
14 include Noscript::AST
15
f4f7a3c @txus add lexer tests
authored
16 def tokenizes(input, expected)
debaf37 @txus save a lot of bytes by using implicit namespaces in tests
authored
17 lexer = Parser.new
f4f7a3c @txus add lexer tests
authored
18 lexer.scan_setup(input)
19 tokens = []
20 while token = lexer.next_token
21 tokens << token
22 end
23
24 assert_equal expected, tokens
25 end
fe8075c @txus assignment parser tests
authored
26
27 def parses(input, &block)
debaf37 @txus save a lot of bytes by using implicit namespaces in tests
authored
28 parser = Parser.new
ff096f7 @txus more tests, regend parser
authored
29
30 show_tokens(input) if ENV['DEBUG']
31
b1df6fe @txus Add filename to the parser
authored
32 ast = parser.parse_string(input, "(test)")
ccd71a5 @txus Update parser tests
authored
33 block.call(ast.body.expressions)
fe8075c @txus assignment parser tests
authored
34 end
35
ac8af93 @txus Compile way more stuff in kernel/test_case
authored
36 def compile(code)
37 Noscript.eval_noscript(code)
38 end
39
40 def assert_output(stdout = nil, stderr = nil)
41 out, err = capture_io do
42 yield
43 end
44
45 y = assert_equal stderr, err, "In stderr" if stderr
46 x = assert_equal stdout, out, "In stdout" if stdout
47
48 (!stdout || x) && (!stderr || y)
49 end
50
ff096f7 @txus more tests, regend parser
authored
51 private
52
53 def show_tokens(input)
debaf37 @txus save a lot of bytes by using implicit namespaces in tests
authored
54 lexer = Parser.new
ff096f7 @txus more tests, regend parser
authored
55 lexer.scan_setup(input.strip)
56 tokens = []
57 while token = lexer.next_token
58 tokens << token
59 end
60 p tokens
61 end
62
63 def show_ast(input)
debaf37 @txus save a lot of bytes by using implicit namespaces in tests
authored
64 parser = Parser.new
ff096f7 @txus more tests, regend parser
authored
65 ast = parser.scan_str(input.strip)
66 p ast
67 end
f4f7a3c @txus add lexer tests
authored
68 end
Something went wrong with that request. Please try again.