laser 0.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE +661 -0
- data/README.md +158 -0
- data/Rakefile +104 -0
- data/VERSION +1 -0
- data/bin/laser +7 -0
- data/design_docs/goals.md +57 -0
- data/design_docs/object_regex.md +426 -0
- data/design_docs/type_annotations.md +80 -0
- data/ext/laser/BasicBlock.cpp +572 -0
- data/ext/laser/BasicBlock.h +118 -0
- data/ext/laser/extconf.rb +3 -0
- data/features/laser.feature +25 -0
- data/features/step_definitions/laser_steps.rb +39 -0
- data/features/support/env.rb +14 -0
- data/features/support/testdata/1_input +1 -0
- data/features/support/testdata/1_output +1 -0
- data/features/support/testdata/2_input +4 -0
- data/features/support/testdata/2_output +4 -0
- data/features/support/testdata/3_input +8 -0
- data/features/support/testdata/3_output +11 -0
- data/features/support/testdata/4_input +5 -0
- data/features/support/testdata/4_output +5 -0
- data/features/support/testdata/5_input +13 -0
- data/laser.gemspec +382 -0
- data/lib/laser.rb +98 -0
- data/lib/laser/analysis/annotations.rb +95 -0
- data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
- data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
- data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
- data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
- data/lib/laser/analysis/argument_expansion.rb +132 -0
- data/lib/laser/analysis/arity.rb +34 -0
- data/lib/laser/analysis/bindings.rb +144 -0
- data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
- data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
- data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
- data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
- data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
- data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
- data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
- data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
- data/lib/laser/analysis/comments.rb +35 -0
- data/lib/laser/analysis/control_flow.rb +28 -0
- data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
- data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
- data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
- data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
- data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
- data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
- data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
- data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
- data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
- data/lib/laser/analysis/control_flow/simulation.rb +385 -0
- data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
- data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
- data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
- data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
- data/lib/laser/analysis/errors.rb +131 -0
- data/lib/laser/analysis/laser_utils.rb +18 -0
- data/lib/laser/analysis/lexical_analysis.rb +172 -0
- data/lib/laser/analysis/method_call.rb +68 -0
- data/lib/laser/analysis/protocol_registry.rb +30 -0
- data/lib/laser/analysis/scope.rb +118 -0
- data/lib/laser/analysis/sexp.rb +159 -0
- data/lib/laser/analysis/sexp_analysis.rb +40 -0
- data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
- data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
- data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
- data/lib/laser/analysis/signature.rb +76 -0
- data/lib/laser/analysis/special_methods/send.rb +67 -0
- data/lib/laser/analysis/unused_methods.rb +21 -0
- data/lib/laser/analysis/visitor.rb +141 -0
- data/lib/laser/annotation_parser/annotations.treetop +126 -0
- data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
- data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
- data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
- data/lib/laser/annotation_parser/overload.treetop +24 -0
- data/lib/laser/annotation_parser/overload_parser.rb +167 -0
- data/lib/laser/annotation_parser/parsers.rb +6 -0
- data/lib/laser/annotation_parser/structural.treetop +37 -0
- data/lib/laser/annotation_parser/structural_parser.rb +406 -0
- data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
- data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
- data/lib/laser/rake/task.rb +46 -0
- data/lib/laser/runner.rb +189 -0
- data/lib/laser/scanner.rb +169 -0
- data/lib/laser/standard_library/_thread.rb +110 -0
- data/lib/laser/standard_library/abbrev.rb +103 -0
- data/lib/laser/standard_library/array.rb +418 -0
- data/lib/laser/standard_library/base64.rb +91 -0
- data/lib/laser/standard_library/basic_object.rb +55 -0
- data/lib/laser/standard_library/benchmark.rb +556 -0
- data/lib/laser/standard_library/bignum.rb +185 -0
- data/lib/laser/standard_library/cgi.rb +275 -0
- data/lib/laser/standard_library/cgi/cookie.rb +147 -0
- data/lib/laser/standard_library/cgi/core.rb +791 -0
- data/lib/laser/standard_library/cgi/html.rb +1021 -0
- data/lib/laser/standard_library/cgi/session.rb +537 -0
- data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
- data/lib/laser/standard_library/cgi/util.rb +188 -0
- data/lib/laser/standard_library/class_definitions.rb +333 -0
- data/lib/laser/standard_library/comparable.rb +125 -0
- data/lib/laser/standard_library/complex.rb +162 -0
- data/lib/laser/standard_library/enumerable.rb +178 -0
- data/lib/laser/standard_library/exceptions.rb +135 -0
- data/lib/laser/standard_library/fixnum.rb +188 -0
- data/lib/laser/standard_library/float.rb +180 -0
- data/lib/laser/standard_library/hash.rb +237 -0
- data/lib/laser/standard_library/integer.rb +123 -0
- data/lib/laser/standard_library/laser_magic.rb +7 -0
- data/lib/laser/standard_library/nil_false_true.rb +113 -0
- data/lib/laser/standard_library/numbers.rb +192 -0
- data/lib/laser/standard_library/proc.rb +31 -0
- data/lib/laser/standard_library/set.rb +1348 -0
- data/lib/laser/standard_library/string.rb +666 -0
- data/lib/laser/standard_library/stringio.rb +2 -0
- data/lib/laser/standard_library/symbol.rb +125 -0
- data/lib/laser/standard_library/tsort.rb +242 -0
- data/lib/laser/support/acts_as_struct.rb +66 -0
- data/lib/laser/support/frequency.rb +55 -0
- data/lib/laser/support/inheritable_attributes.rb +145 -0
- data/lib/laser/support/module_extensions.rb +94 -0
- data/lib/laser/support/placeholder_object.rb +13 -0
- data/lib/laser/third_party/rgl/adjacency.rb +221 -0
- data/lib/laser/third_party/rgl/base.rb +228 -0
- data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
- data/lib/laser/third_party/rgl/condensation.rb +47 -0
- data/lib/laser/third_party/rgl/connected_components.rb +138 -0
- data/lib/laser/third_party/rgl/control_flow.rb +170 -0
- data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
- data/lib/laser/third_party/rgl/dominators.rb +124 -0
- data/lib/laser/third_party/rgl/dot.rb +93 -0
- data/lib/laser/third_party/rgl/graphxml.rb +51 -0
- data/lib/laser/third_party/rgl/implicit.rb +174 -0
- data/lib/laser/third_party/rgl/mutable.rb +117 -0
- data/lib/laser/third_party/rgl/rdot.rb +445 -0
- data/lib/laser/third_party/rgl/topsort.rb +72 -0
- data/lib/laser/third_party/rgl/transitivity.rb +180 -0
- data/lib/laser/third_party/rgl/traversal.rb +348 -0
- data/lib/laser/types/types.rb +433 -0
- data/lib/laser/version.rb +14 -0
- data/lib/laser/warning.rb +149 -0
- data/lib/laser/warning_sets/default.yml +13 -0
- data/lib/laser/warnings/assignment_in_condition.rb +20 -0
- data/lib/laser/warnings/comment_spacing.rb +31 -0
- data/lib/laser/warnings/extra_blank_lines.rb +30 -0
- data/lib/laser/warnings/extra_whitespace.rb +16 -0
- data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
- data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
- data/lib/laser/warnings/line_length.rb +115 -0
- data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
- data/lib/laser/warnings/operator_spacing.rb +68 -0
- data/lib/laser/warnings/parens_on_declaration.rb +30 -0
- data/lib/laser/warnings/rescue_exception.rb +42 -0
- data/lib/laser/warnings/semicolon.rb +25 -0
- data/lib/laser/warnings/sexp_errors.rb +24 -0
- data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
- data/lib/laser/warnings/useless_double_quotes.rb +38 -0
- data/spec/analysis_specs/annotations_spec.rb +47 -0
- data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
- data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
- data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
- data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
- data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
- data/spec/analysis_specs/bindings_spec.rb +36 -0
- data/spec/analysis_specs/comment_spec.rb +93 -0
- data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
- data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
- data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
- data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
- data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
- data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
- data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
- data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
- data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
- data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
- data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
- data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
- data/spec/analysis_specs/error_spec.rb +30 -0
- data/spec/analysis_specs/laser_class_spec.rb +322 -0
- data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
- data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
- data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
- data/spec/analysis_specs/scope_spec.rb +126 -0
- data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
- data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
- data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
- data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
- data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
- data/spec/analysis_specs/sexp_spec.rb +167 -0
- data/spec/analysis_specs/spec_helper.rb +27 -0
- data/spec/analysis_specs/unused_methods_spec.rb +65 -0
- data/spec/analysis_specs/visitor_spec.rb +64 -0
- data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
- data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
- data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
- data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
- data/spec/annotation_parser_specs/spec_helper.rb +1 -0
- data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
- data/spec/laser_spec.rb +14 -0
- data/spec/rake_specs/spec_helper.rb +1 -0
- data/spec/rake_specs/task_spec.rb +67 -0
- data/spec/runner_spec.rb +207 -0
- data/spec/scanner_spec.rb +75 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/standard_library/exceptions_spec.rb +19 -0
- data/spec/standard_library/globals_spec.rb +14 -0
- data/spec/standard_library/set_spec.rb +31 -0
- data/spec/standard_library/spec_helper.rb +1 -0
- data/spec/standard_library/standard_library_spec.rb +302 -0
- data/spec/support_specs/acts_as_struct_spec.rb +94 -0
- data/spec/support_specs/frequency_spec.rb +23 -0
- data/spec/support_specs/module_extensions_spec.rb +117 -0
- data/spec/support_specs/spec_helper.rb +1 -0
- data/spec/type_specs/spec_helper.rb +1 -0
- data/spec/type_specs/types_spec.rb +133 -0
- data/spec/warning_spec.rb +95 -0
- data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
- data/spec/warning_specs/comment_spacing_spec.rb +65 -0
- data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
- data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
- data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
- data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
- data/spec/warning_specs/line_length_spec.rb +173 -0
- data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
- data/spec/warning_specs/operator_spacing_spec.rb +104 -0
- data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
- data/spec/warning_specs/rescue_exception_spec.rb +105 -0
- data/spec/warning_specs/semicolon_spec.rb +58 -0
- data/spec/warning_specs/spec_helper.rb +1 -0
- data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
- data/status_reports/2010/12/2010-12-14.md +163 -0
- data/status_reports/2010/12/2010-12-23.md +298 -0
- data/status_reports/2010/12/2010-12-24.md +6 -0
- data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
- data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
- data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
- data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
- data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
- data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
- data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
- data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
- data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
- data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
- data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
- data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
- data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
- data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
- data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
- metadata +470 -0
@@ -0,0 +1,231 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Sexp do
|
4
|
+
describe '#source_begin/#source_end' do
|
5
|
+
# [:program,
|
6
|
+
# [[:assign,
|
7
|
+
# [:var_field, [:@ident, "arr", [1, 0]]],
|
8
|
+
# [:mrhs_new_from_args,
|
9
|
+
# [[:var_ref, [:@kw, "true", [1, 6]]],
|
10
|
+
# [:var_ref, [:@kw, "nil", [1, 12]]],
|
11
|
+
# [:@int, "314", [1, 17]],
|
12
|
+
# [:@float, "4.155", [1, 22]],
|
13
|
+
# [:@CHAR, "?x", [1, 29]],
|
14
|
+
# [:regexp_literal,
|
15
|
+
# [[:@tstring_content, "ac", [1, 34]]],
|
16
|
+
# [:@regexp_end, "/ix", [1, 36]]],
|
17
|
+
# [:string_literal,
|
18
|
+
# [:string_content,
|
19
|
+
# [:@tstring_content, "Abc", [1, 42]],
|
20
|
+
# [:string_embexpr, [[:var_ref, [:@ident, "hi", [1, 47]]]]]]],
|
21
|
+
# [:dyna_symbol,
|
22
|
+
# [[:@tstring_content, "hello ", [1, 55]],
|
23
|
+
# [:string_embexpr, [[:var_ref, [:@ident, "there", [1, 63]]]]]]]],
|
24
|
+
# [:hash,
|
25
|
+
# [:assoclist_from_args,
|
26
|
+
# [[:assoc_new,
|
27
|
+
# [:@label, "a:", [1, 74]],
|
28
|
+
# [:symbol_literal, [:symbol, [:@ident, "b", [1, 78]]]]]]]]]]]]
|
29
|
+
|
30
|
+
it 'discovers the source begin location for a variety of literals and their containing nodes' do
|
31
|
+
input = 'arr = true, nil, 314, 4.155, ?x, /ac/ix, "Abc#{hi}", :"hello #{there}", { a: :b }'
|
32
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
33
|
+
list = tree[1]
|
34
|
+
|
35
|
+
list[0][1][1].source_begin.should == [1, 0]
|
36
|
+
list[0][1].source_begin.should == [1, 0]
|
37
|
+
list[0].source_begin.should == [1, 0]
|
38
|
+
|
39
|
+
arglist = list[0][2]
|
40
|
+
arglist.source_begin.should == [1, 6]
|
41
|
+
args = arglist[1]
|
42
|
+
# true
|
43
|
+
args[0].source_begin.should == [1, 6]
|
44
|
+
args[0][1].source_begin.should == [1, 6]
|
45
|
+
# nil
|
46
|
+
args[1].source_begin.should == [1, 12]
|
47
|
+
args[1][1].source_begin.should == [1, 12]
|
48
|
+
# 314
|
49
|
+
args[2].source_begin.should == [1, 17]
|
50
|
+
# 4.155
|
51
|
+
args[3].source_begin.should == [1, 22]
|
52
|
+
# ?x
|
53
|
+
args[4].source_begin.should == [1, 29]
|
54
|
+
# /ac/ix
|
55
|
+
args[5].source_begin.should == [1, 33]
|
56
|
+
args[5][1].source_begin.should == [1, 34]
|
57
|
+
args[5][1][0].source_begin.should == [1, 34]
|
58
|
+
args[5][2].source_begin.should == [1, 36]
|
59
|
+
# "Abc#{hi}"
|
60
|
+
args[6].source_begin.should == [1, 41]
|
61
|
+
args[6][1].source_begin.should == [1, 42]
|
62
|
+
args[6][1][1].source_begin.should == [1, 42]
|
63
|
+
args[6][1][2].source_begin.should == [1, 45]
|
64
|
+
args[6][1][2][1].source_begin.should == [1, 47]
|
65
|
+
args[6][1][2][1][0].source_begin.should == [1, 47]
|
66
|
+
args[6][1][2][1][0][1].source_begin.should == [1, 47]
|
67
|
+
# :"hello #{there}"
|
68
|
+
args[7].source_begin.should == [1, 53]
|
69
|
+
args[7][1].source_begin.should == [1, 55]
|
70
|
+
args[7][1][0].source_begin.should == [1, 55]
|
71
|
+
args[7][1][1].source_begin.should == [1, 61]
|
72
|
+
args[7][1][1][1].source_begin.should == [1, 63]
|
73
|
+
args[7][1][1][1][0].source_begin.should == [1, 63]
|
74
|
+
args[7][1][1][1][0][1].source_begin.should == [1, 63]
|
75
|
+
|
76
|
+
# { a: :b }
|
77
|
+
hash = arglist[2]
|
78
|
+
hash.source_begin.should == [1, 72]
|
79
|
+
hash[1].source_begin.should == [1, 74]
|
80
|
+
hash[1][1].source_begin.should == [1, 74]
|
81
|
+
hash[1][1][0].source_begin.should == [1, 74]
|
82
|
+
hash[1][1][0][1].source_begin.should == [1, 74]
|
83
|
+
hash[1][1][0][2].source_begin.should == [1, 77]
|
84
|
+
hash[1][1][0][2][1].source_begin.should == [1, 78]
|
85
|
+
hash[1][1][0][2][1][1].source_begin.should == [1, 78]
|
86
|
+
end
|
87
|
+
|
88
|
+
# [:program,
|
89
|
+
# [[:assign,
|
90
|
+
# [:var_field, [:@ident, "arr", [1, 0]]],
|
91
|
+
# [:mrhs_new_from_args,
|
92
|
+
# [[:var_ref, [:@kw, "true", [1, 6]]],
|
93
|
+
# [:var_ref, [:@kw, "nil", [1, 12]]],
|
94
|
+
# [:@int, "314", [1, 17]],
|
95
|
+
# [:@float, "4.155", [1, 22]],
|
96
|
+
# [:@CHAR, "?x", [1, 29]],
|
97
|
+
# [:regexp_literal,
|
98
|
+
# [[:@tstring_content, "ac", [1, 34]]],
|
99
|
+
# [:@regexp_end, "/ix", [1, 36]]],
|
100
|
+
# [:string_literal,
|
101
|
+
# [:string_content,
|
102
|
+
# [:@tstring_content, "Abc", [1, 42]],
|
103
|
+
# [:string_embexpr, [[:var_ref, [:@ident, "hi", [1, 47]]]]]]],
|
104
|
+
# [:dyna_symbol,
|
105
|
+
# [[:@tstring_content, "hello ", [1, 55]],
|
106
|
+
# [:string_embexpr, [[:var_ref, [:@ident, "there", [1, 63]]]]]]]],
|
107
|
+
# [:hash,
|
108
|
+
# [:assoclist_from_args,
|
109
|
+
# [[:assoc_new,
|
110
|
+
# [:@label, "a:", [1, 74]],
|
111
|
+
# [:symbol_literal, [:symbol, [:@ident, "b", [1, 78]]]]]]]]]]]]
|
112
|
+
|
113
|
+
it 'discovers the source end location for a variety of literals and their containing nodes' do
|
114
|
+
input = 'arr = true, nil, 314, 4.155, ?x, /ac/ix, "Abc#{hi}", :"hello #{there}", { a: :b }'
|
115
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
116
|
+
list = tree[1]
|
117
|
+
|
118
|
+
list[0][1][1].source_end.should == [1, 3]
|
119
|
+
list[0][1].source_end.should == [1, 3]
|
120
|
+
list[0].source_end.should == [1, 81] # requires that we get the hash right, which we don't. TODO(adgar)
|
121
|
+
|
122
|
+
arglist = list[0][2]
|
123
|
+
arglist.source_end.should == [1, 81] # for all rhs, requires forward-tracking
|
124
|
+
args = arglist[1]
|
125
|
+
args[0].source_end.should == [1, 10]
|
126
|
+
args[0][1].source_end.should == [1, 10]
|
127
|
+
args[1].source_end.should == [1, 15]
|
128
|
+
args[1][1].source_end.should == [1, 15]
|
129
|
+
args[2].source_end.should == [1, 20]
|
130
|
+
args[3].source_end.should == [1, 27]
|
131
|
+
args[4].source_end.should == [1, 31]
|
132
|
+
args[5].source_end.should == [1, 39]
|
133
|
+
args[5][1].source_end.should == [1, 36]
|
134
|
+
args[5][1][0].source_end.should == [1, 36]
|
135
|
+
args[5][2].source_end.should == [1, 39]
|
136
|
+
args[6].source_end.should == [1, 51]
|
137
|
+
args[6][1].source_end.should == [1, 50]
|
138
|
+
args[6][1][1].source_end.should == [1, 45]
|
139
|
+
args[6][1][2].source_end.should == [1, 50]
|
140
|
+
args[6][1][2][1].source_end.should == [1, 49]
|
141
|
+
args[6][1][2][1][0].source_end.should == [1, 49]
|
142
|
+
args[6][1][2][1][0][1].source_end.should == [1, 49]
|
143
|
+
args[7].source_end.should == [1, 70]
|
144
|
+
args[7][1].source_end.should == [1, 69]
|
145
|
+
args[7][1][0].source_end.should == [1, 61]
|
146
|
+
args[7][1][1].source_end.should == [1, 69]
|
147
|
+
args[7][1][1][1].source_end.should == [1, 68]
|
148
|
+
args[7][1][1][1][0].source_end.should == [1, 68]
|
149
|
+
args[7][1][1][1][0][1].source_end.should == [1, 68]
|
150
|
+
#
|
151
|
+
hash = arglist[2]
|
152
|
+
hash.source_end.should == [1, 81]
|
153
|
+
hash[1].source_end.should == [1, 79]
|
154
|
+
hash[1][1].source_end.should == [1, 79]
|
155
|
+
hash[1][1][0].source_end.should == [1, 79]
|
156
|
+
hash[1][1][0][1].source_end.should == [1, 76]
|
157
|
+
hash[1][1][0][2].source_end.should == [1, 79]
|
158
|
+
hash[1][1][0][2][1].source_end.should == [1, 79]
|
159
|
+
hash[1][1][0][2][1][1].source_end.should == [1, 79]
|
160
|
+
end
|
161
|
+
|
162
|
+
# [:program,
|
163
|
+
# [[:assign,
|
164
|
+
# [:var_field, [:@ident, "arr", [1, 0]]],
|
165
|
+
# [:array, [[:@int, "1", [1, 8]], [:@int, "2", [2, 0]]]]]]]
|
166
|
+
|
167
|
+
it 'discovers the locations of array literals' do
|
168
|
+
input = "arr = [ 1, \n2 ]"
|
169
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
170
|
+
assign = tree[1][0]
|
171
|
+
assign.source_begin.should == [1, 0]
|
172
|
+
assign[1].source_begin.should == [1, 0]
|
173
|
+
assign[1].source_end.should == [1, 3]
|
174
|
+
assign[2].source_begin.should == [1, 6]
|
175
|
+
assign[2].source_end.should == [2, 3]
|
176
|
+
end
|
177
|
+
|
178
|
+
# [:program,
|
179
|
+
# [[:def,
|
180
|
+
# [:@ident, "abc", [2, 0]],
|
181
|
+
# [:params, nil, nil, nil, nil, nil],
|
182
|
+
# [:bodystmt,
|
183
|
+
# [[:assign, [:var_field, [:@ident, "x", [3, 2]]], [:@int, "10", [3, 6]]]],
|
184
|
+
# nil, nil, nil]]]]
|
185
|
+
it 'discovers the locations of method definitons' do
|
186
|
+
input = " def \nabc\n x = 10\n end"
|
187
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
188
|
+
definition = tree[1][0]
|
189
|
+
definition.source_begin.should == [1, 1]
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'discovers the locations of operator definitons' do
|
193
|
+
input = " def <=>(other)\n x = 10\n end"
|
194
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
195
|
+
definition = tree[1][0]
|
196
|
+
definition.source_begin.should == [1, 1]
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'discovers the locations of singleton method definitons' do
|
200
|
+
input = " def \n self.abc\n x = 10\n end"
|
201
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
202
|
+
definition = tree[1][0]
|
203
|
+
definition.source_begin.should == [1, 1]
|
204
|
+
end
|
205
|
+
|
206
|
+
# [:program,
|
207
|
+
# [[:class,
|
208
|
+
# [:const_ref, [:@const, "A", [2, 0]]],
|
209
|
+
# [:var_ref, [:@const, "B", [2, 4]]],
|
210
|
+
# [:bodystmt,
|
211
|
+
# [[:module,
|
212
|
+
# [:const_ref, [:@const, "D", [4, 0]]],
|
213
|
+
# [:bodystmt, [[:void_stmt]], nil, nil, nil]]],
|
214
|
+
# nil, nil, nil]]]]
|
215
|
+
it 'discovers the locations of class and module definitons' do
|
216
|
+
input = " class\nA < B; module\n\nD;end\n end"
|
217
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
218
|
+
klass = tree[1][0]
|
219
|
+
klass.source_begin.should == [1, 3]
|
220
|
+
klass[3][1][0].source_begin.should == [2, 7]
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'discovers the locations of singleton class definitons' do
|
224
|
+
input = " class\nA < B; class <<\nB;end\n end"
|
225
|
+
tree = Sexp.new(Ripper.sexp(input), '(stdin)', input)
|
226
|
+
klass = tree[1][0]
|
227
|
+
klass.source_begin.should == [1, 3]
|
228
|
+
klass[3][1][0].source_begin.should == [2, 9]
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../spec_helper'
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Sexp do
|
4
|
+
describe '#expr_type' do
|
5
|
+
# This is the AST that Ripper generates for the parsed code. It is
|
6
|
+
# provided here because otherwise the test is inscrutable.
|
7
|
+
#
|
8
|
+
# [:program,
|
9
|
+
# [[:assign,
|
10
|
+
# [:var_field, [:@ident, "a", [1, 0]]], [:@int, "5", [1, 4]]]]]
|
11
|
+
it 'discovers the class for integer literals' do
|
12
|
+
tree = Sexp.new(Ripper.sexp('a = 5'))
|
13
|
+
list = tree[1]
|
14
|
+
list[0][2].expr_type.should == Types::ClassType.new('Integer', :covariant)
|
15
|
+
end
|
16
|
+
|
17
|
+
# This is the AST that Ripper generates for the parsed code. It is
|
18
|
+
# provided here because otherwise the test is inscrutable.
|
19
|
+
#
|
20
|
+
# [:program,
|
21
|
+
# [[:assign,
|
22
|
+
# [:var_field, [:@ident, "a", [1, 0]]],
|
23
|
+
# [:string_literal,
|
24
|
+
# [:string_content,
|
25
|
+
# [:@tstring_content, "abc = ", [1, 5]],
|
26
|
+
# [:string_embexpr,
|
27
|
+
# [[:binary,
|
28
|
+
# [:var_ref, [:@ident, "run_method", [1, 13]]],
|
29
|
+
# :-,
|
30
|
+
# [:@int, "5", [1, 26]]]]]]]]]]
|
31
|
+
it 'discovers the class for nontrivial string literals' do
|
32
|
+
tree = Sexp.new(Ripper.sexp('a = "abc = #{run_method - 5}"'))
|
33
|
+
list = tree[1]
|
34
|
+
[list[0][2], list[0][2][1], list[0][2][1][1], list[0][2][1][2]].each do |entry|
|
35
|
+
entry.expr_type.should == Types::ClassType.new('String', :invariant)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# [:program,
|
40
|
+
# [[:assign,
|
41
|
+
# [:var_field, [:@ident, "a", [1, 0]]],
|
42
|
+
# [:xstring_literal, [[:@tstring_content, "find .", [1, 7]]]]]]]
|
43
|
+
it 'discovers the class for executed string literals' do
|
44
|
+
tree = Sexp.new(Ripper.sexp('a = %x(find .)'))
|
45
|
+
list = tree[1]
|
46
|
+
list[0][2].expr_type.should == Types::ClassType.new('String', :invariant)
|
47
|
+
end
|
48
|
+
|
49
|
+
# [:program,
|
50
|
+
# [[:assign,
|
51
|
+
# [:var_field, [:@ident, "a", [1, 0]]],
|
52
|
+
# [:@CHAR, "?a", [1, 4]]]]]
|
53
|
+
it 'discovers the class for character literals' do
|
54
|
+
tree = Sexp.new(Ripper.sexp('a = ?a'))
|
55
|
+
list = tree[1]
|
56
|
+
list[0][2].expr_type.should == Types::ClassType.new('String', :invariant)
|
57
|
+
end
|
58
|
+
|
59
|
+
# [:program,
|
60
|
+
# [[:assign,
|
61
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
62
|
+
# [:@float, "3.14", [1, 4]]]]]
|
63
|
+
it 'discovers the class for float literals' do
|
64
|
+
tree = Sexp.new(Ripper.sexp('x = 3.14'))
|
65
|
+
list = tree[1]
|
66
|
+
list[0][2].expr_type.should == Types::ClassType.new('Float', :invariant)
|
67
|
+
end
|
68
|
+
|
69
|
+
# [:program,
|
70
|
+
# [[:assign,
|
71
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
72
|
+
# [:regexp_literal,
|
73
|
+
# [[:@tstring_content, "abc", [1, 5]]],
|
74
|
+
# [:@regexp_end, "/im", [1, 8]]]]]]
|
75
|
+
it 'discovers the class for regexp literals' do
|
76
|
+
tree = Sexp.new(Ripper.sexp('x = /abc/im'))
|
77
|
+
list = tree[1]
|
78
|
+
list[0][2].expr_type.should == Types::ClassType.new('Regexp', :invariant)
|
79
|
+
end
|
80
|
+
|
81
|
+
# [:program,
|
82
|
+
# [[:assign,
|
83
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
84
|
+
# [:array, [[:@int, "1", [1, 5]], [:@int, "2", [1, 8]]]]]]]
|
85
|
+
it 'discovers the class for array literals' do
|
86
|
+
tree = Sexp.new(Ripper.sexp('x = [1, 2]'))
|
87
|
+
list = tree[1]
|
88
|
+
list[0][2].expr_type.should == Types::ClassType.new('Array', :invariant)
|
89
|
+
end
|
90
|
+
|
91
|
+
# [:program,
|
92
|
+
# [[:assign,
|
93
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
94
|
+
# [:hash,
|
95
|
+
# [:assoclist_from_args,
|
96
|
+
# [[:assoc_new,
|
97
|
+
# [:@label, "a:", [1, 5]],
|
98
|
+
# [:symbol_literal, [:symbol, [:@ident, "b", [1, 9]]]]]]]]]]]
|
99
|
+
it 'discovers the class for hash literals' do
|
100
|
+
tree = Sexp.new(Ripper.sexp('x = {a: :b}'))
|
101
|
+
list = tree[1]
|
102
|
+
list[0][2].expr_type.should == Types::ClassType.new('Hash', :invariant)
|
103
|
+
end
|
104
|
+
|
105
|
+
# [:program,
|
106
|
+
# [[:method_add_arg,
|
107
|
+
# [:fcall, [:@ident, "p", [1, 0]]],
|
108
|
+
# [:arg_paren,
|
109
|
+
# [:args_add_block,
|
110
|
+
# [[:bare_assoc_hash,
|
111
|
+
# [[:assoc_new, [:@label, "a:", [1, 2]], [:@int, "3", [1, 5]]],
|
112
|
+
# [:assoc_new, [:@label, "b:", [1, 8]], [:@int, "3", [1, 11]]]]]],
|
113
|
+
# false]]]]]
|
114
|
+
it 'discovers the class for hash literals using the no-brace shorthand' do
|
115
|
+
tree = Sexp.new(Ripper.sexp('p(a: 3, b: 3)'))
|
116
|
+
list = tree[1]
|
117
|
+
list[0][2][1][1][0].expr_type.should == Types::ClassType.new('Hash', :invariant)
|
118
|
+
end
|
119
|
+
|
120
|
+
# [:program,
|
121
|
+
# [[:assign,
|
122
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
123
|
+
# [:symbol_literal, [:symbol, [:@ident, "abcdef", [1, 5]]]]]]]
|
124
|
+
it 'discovers the class for symbol literals' do
|
125
|
+
tree = Sexp.new(Ripper.sexp('x = :abcdef'))
|
126
|
+
list = tree[1]
|
127
|
+
list[0][2].expr_type.should == Types::ClassType.new('Symbol', :invariant)
|
128
|
+
end
|
129
|
+
|
130
|
+
# [:program,
|
131
|
+
# [[:assign,
|
132
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
133
|
+
# [:dyna_symbol,
|
134
|
+
# [[:@tstring_content, "abc", [1, 6]],
|
135
|
+
# [:string_embexpr, [[:var_ref, [:@ident, "xyz", [1, 11]]]]],
|
136
|
+
# [:@tstring_content, "def", [1, 15]]]]]]]
|
137
|
+
it 'discovers the class for dynamic symbol literals' do
|
138
|
+
tree = Sexp.new(Ripper.sexp('x = :"abc{xyz}def"'))
|
139
|
+
list = tree[1]
|
140
|
+
list[0][2].expr_type.should == Types::ClassType.new('Symbol', :invariant)
|
141
|
+
end
|
142
|
+
|
143
|
+
# [:program,
|
144
|
+
# [[:assign,
|
145
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
146
|
+
# [:hash,
|
147
|
+
# [:assoclist_from_args,
|
148
|
+
# [[:assoc_new,
|
149
|
+
# [:@label, "a:", [1, 5]],
|
150
|
+
# [:symbol_literal, [:symbol, [:@ident, "b", [1, 9]]]]]]]]]]]
|
151
|
+
it 'discovers the class for the label-style symbols in Ruby 1.9' do
|
152
|
+
tree = Sexp.new(Ripper.sexp('x = {a: :b}'))
|
153
|
+
list = tree[1]
|
154
|
+
list[0][2][1][1][0][1].expr_type.should == Types::ClassType.new('Symbol', :invariant)
|
155
|
+
end
|
156
|
+
|
157
|
+
# [:program,
|
158
|
+
# [[:assign,
|
159
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
160
|
+
# [:var_ref, [:@kw, "true", [1, 4]]]]]]
|
161
|
+
it 'discovers the class for true' do
|
162
|
+
tree = Sexp.new(Ripper.sexp('x = true'))
|
163
|
+
list = tree[1]
|
164
|
+
list[0][2].expr_type.should == Types::ClassType.new('TrueClass', :invariant)
|
165
|
+
end
|
166
|
+
|
167
|
+
# [:program,
|
168
|
+
# [[:assign,
|
169
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
170
|
+
# [:var_ref, [:@kw, "false", [1, 4]]]]]]
|
171
|
+
it 'discovers the class for false' do
|
172
|
+
tree = Sexp.new(Ripper.sexp('x = false'))
|
173
|
+
list = tree[1]
|
174
|
+
list[0][2].expr_type.should == Types::ClassType.new('FalseClass', :invariant)
|
175
|
+
end
|
176
|
+
|
177
|
+
# [:program,
|
178
|
+
# [[:assign,
|
179
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
180
|
+
# [:var_ref, [:@kw, "nil", [1, 4]]]]]]
|
181
|
+
it 'discovers the class for nil' do
|
182
|
+
tree = Sexp.new(Ripper.sexp('x = nil'))
|
183
|
+
list = tree[1]
|
184
|
+
list[0][2].expr_type.should == Types::ClassType.new('NilClass', :invariant)
|
185
|
+
end
|
186
|
+
|
187
|
+
# [:program,
|
188
|
+
# [[:assign,
|
189
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
190
|
+
# [:var_ref, [:@kw, "__FILE__", [1, 4]]]]]]
|
191
|
+
it 'discovers the class for __FILE__' do
|
192
|
+
tree = Sexp.new(Ripper.sexp('x = __FILE__'))
|
193
|
+
list = tree[1]
|
194
|
+
list[0][2].expr_type.should == Types::ClassType.new('String', :invariant)
|
195
|
+
end
|
196
|
+
|
197
|
+
# [:program,
|
198
|
+
# [[:assign,
|
199
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
200
|
+
# [:var_ref, [:@kw, "__LINE__", [1, 4]]]]]]
|
201
|
+
it 'discovers the class for __LINE__' do
|
202
|
+
tree = Sexp.new(Ripper.sexp('x = __LINE__'))
|
203
|
+
list = tree[1]
|
204
|
+
list[0][2].expr_type.should == Types::ClassType.new('Fixnum', :invariant)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
# [:program,
|
209
|
+
# [[:assign,
|
210
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
211
|
+
# [:var_ref, [:@kw, "__LINE__", [1, 4]]]]]]
|
212
|
+
it 'discovers the class for __ENCODING__' do
|
213
|
+
tree = Sexp.new(Ripper.sexp('x = __ENCODING__'))
|
214
|
+
list = tree[1]
|
215
|
+
list[0][2].expr_type.should == Types::ClassType.new('Encoding', :invariant)
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
# [:program,
|
220
|
+
# [[:assign,
|
221
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
222
|
+
# [:dot2, [:@int, "2", [1, 4]], [:@int, "9", [1, 7]]]]]]
|
223
|
+
it 'discovers the class for inclusive ranges' do
|
224
|
+
tree = Sexp.new(Ripper.sexp('x = 2..9'))
|
225
|
+
list = tree[1]
|
226
|
+
list[0][2].expr_type.should == Types::ClassType.new('Range', :invariant)
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
# [:program,
|
231
|
+
# [[:assign,
|
232
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
233
|
+
# [:dot3, [:@int, "2", [1, 4]], [:@int, "9", [1, 8]]]]]]
|
234
|
+
it 'discovers the class for exclusive ranges' do
|
235
|
+
tree = Sexp.new(Ripper.sexp('x = 2...9'))
|
236
|
+
list = tree[1]
|
237
|
+
list[0][2].expr_type.should == Types::ClassType.new('Range', :invariant)
|
238
|
+
end
|
239
|
+
|
240
|
+
# [:program,
|
241
|
+
# [[:assign,
|
242
|
+
# [:var_field, [:@ident, "x", [1, 0]]],
|
243
|
+
# [:lambda,
|
244
|
+
# [:paren, [:params, [[:@ident, "a", [1, 7]]], nil, nil, nil, nil]],
|
245
|
+
# [[:var_ref, [:@ident, "a", [1, 10]]]]]]]]
|
246
|
+
it "discovers the class for 1.9's stabby lambdas" do
|
247
|
+
tree = Sexp.new(Ripper.sexp('x = ->(a, b=2){ a + b }'))
|
248
|
+
list = tree[1]
|
249
|
+
list[0][2].expr_type.should == Types::ClassType.new('Proc', :invariant)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|