Class: TestRawParseTree
- Inherits:
-
ParseTreeTestCase
- Object
- ParseTreeTestCase
- TestRawParseTree
- Defined in:
- lib/parsetree/test/test_parse_tree.rb
Constant Summary collapse
- @@self_classmethod =
[:defs, [:self], :classmethod, [:scope, [:block, [:args], [:call, [:lit, 1], :+, [:array, [:lit, 1]]]]]]
- @@missing =
[nil]
- @@opt_args =
[:defn, :opt_args, [:scope, [:block, [:args, :arg1, :arg2, :"*args", [:block, [:lasgn, :arg2, [:lit, 42]]]], [:lasgn, :arg3, [:call, [:call, [:lvar, :arg1], :*, [:array, [:lvar, :arg2]]], :*, [:array, [:lit, 7]]]], [:fcall, :puts, [:array, [:call, [:lvar, :arg3], :to_s]]], [:return, [:str, "foo"]]]]]
- @@multi_args =
[:defn, :multi_args, [:scope, [:block, [:args, :arg1, :arg2], [:lasgn, :arg3, [:call, [:call, [:lvar, :arg1], :*, [:array, [:lvar, :arg2]]], :*, [:array, [:lit, 7]]]], [:fcall, :puts, [:array, [:call, [:lvar, :arg3], :to_s]]], [:return, [:str, "foo"]]]]]
- @@unknown_args =
[:defn, :unknown_args, [:scope, [:block, [:args, :arg1, :arg2], [:return, [:lvar, :arg1]]]]]
- @@bbegin =
[:defn, :bbegin, [:scope, [:block, [:args], [:ensure, [:rescue, [:lit, 1], [:resbody, [:array, [:const, :SyntaxError]], [:block, [:lasgn, :e1, [:gvar, :$!]], [:lit, 2]], [:resbody, [:array, [:const, :Exception]], [:block, [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]], [:lit, 4]], [:lit, 5]]]]]
- @@bbegin_no_exception =
[:defn, :bbegin_no_exception, [:scope, [:block, [:args], [:rescue, [:lit, 5], [:resbody, nil, [:lit, 6]]]]]]
- @@determine_args =
[:defn, :determine_args, [:scope, [:block, [:args], [:call, [:lit, 5], :==, [:array, [:fcall, :unknown_args, [:array, [:lit, 4], [:str, "known"]]]]]]]]
- @@attrasgn =
[:defn, :attrasgn, [:scope, [:block, [:args], [:attrasgn, [:lit, 42], :method=, [:array, [:vcall, :y]]], [:attrasgn, [:self], :type=, [:array, [:call, [:vcall, :other], :type]]]]]]
- @@__all =
[:class, :Something, [:const, :Object]]
Instance Method Summary collapse
- #setup ⇒ Object
- #test_class_initialize ⇒ Object
- #test_class_translate_string ⇒ Object
- #test_class_translate_string_method ⇒ Object
- #test_missing ⇒ Object
- #test_parse_tree_for_str ⇒ Object
- #test_parse_tree_for_string ⇒ Object
- #test_parse_tree_for_string_with_newlines ⇒ Object
- #test_process_modules ⇒ Object
- #test_whole_class ⇒ Object
Instance Method Details
#setup ⇒ Object
2335 2336 2337 2338 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2335 def setup super @processor = RawParseTree.new(false) end |
#test_class_initialize ⇒ Object
2349 2350 2351 2352 2353 2354 2355 2356 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2349 def test_class_initialize expected = [[:class, :SomethingWithInitialize, [:const, :Object], [:defn, :initialize, [:scope, [:block, [:args], [:nil]]]], [:defn, :protected_meth, [:scope, [:block, [:args], [:nil]]]], ]] tree = @processor.parse_tree SomethingWithInitialize assert_equal expected, tree end |
#test_class_translate_string ⇒ Object
2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2358 def test_class_translate_string str = "class A; def a; end; end" sexp = ParseTree.translate str expected = [:class, :A, nil, [:scope, [:defn, :a, [:scope, [:block, [:args], [:nil]]]]]] assert_equal expected, sexp end |
#test_class_translate_string_method ⇒ Object
2370 2371 2372 2373 2374 2375 2376 2377 2378 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2370 def test_class_translate_string_method str = "class A; def a; end; def b; end; end" sexp = ParseTree.translate str, :a expected = [:defn, :a, [:scope, [:block, [:args], [:nil]]]] assert_equal expected, sexp end |
#test_missing ⇒ Object
2510 2511 2512 2513 2514 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2510 def test_missing assert_equal(@@missing, @processor.parse_tree_for_method(Something, :missing), "Must return #{@@missing.inspect} for missing methods") end |
#test_parse_tree_for_str ⇒ Object
2387 2388 2389 2390 2391 2392 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2387 def test_parse_tree_for_str actual = @processor.parse_tree_for_str '1 + nil', '(string)', 1 expected = [[:call, [:lit, 1], :+, [:array, [:nil]]]] assert_equal expected, actual end |
#test_parse_tree_for_string ⇒ Object
2380 2381 2382 2383 2384 2385 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2380 def test_parse_tree_for_string actual = @processor.parse_tree_for_string '1 + nil', '(string)', 1 expected = [[:call, [:lit, 1], :+, [:array, [:nil]]]] assert_equal expected, actual end |
#test_parse_tree_for_string_with_newlines ⇒ Object
2340 2341 2342 2343 2344 2345 2346 2347 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2340 def test_parse_tree_for_string_with_newlines @processor = RawParseTree.new(true) actual = @processor.parse_tree_for_string "1 +\n nil", 'test.rb', 5 expected = [[:newline, 6, "test.rb", [:call, [:lit, 1], :+, [:array, [:nil]]]]] assert_equal expected, actual end |
#test_process_modules ⇒ Object
2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2522 def test_process_modules exp = [[:module, :Mod1, [:defn, :mod_method, [:bmethod, nil]]]] assert_equal exp, @processor.parse_tree(Mod1) exp = [[:module, :Mod2, [:fcall, :include, [:array, [:const, :Mod1]]]]] assert_equal exp, @processor.parse_tree(Mod2) exp = [[:class, :ClassInclude, [:const, :Object], [:fcall, :include, [:array, [:const, :Mod2]]]]] assert_equal exp, @processor.parse_tree(ClassInclude) end |
#test_whole_class ⇒ Object
2516 2517 2518 2519 2520 |
# File 'lib/parsetree/test/test_parse_tree.rb', line 2516 def test_whole_class assert_equal([@@__all], @processor.parse_tree(Something), "Must return a lot of shit") end |