laser 0.7.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE +661 -0
  5. data/README.md +158 -0
  6. data/Rakefile +104 -0
  7. data/VERSION +1 -0
  8. data/bin/laser +7 -0
  9. data/design_docs/goals.md +57 -0
  10. data/design_docs/object_regex.md +426 -0
  11. data/design_docs/type_annotations.md +80 -0
  12. data/ext/laser/BasicBlock.cpp +572 -0
  13. data/ext/laser/BasicBlock.h +118 -0
  14. data/ext/laser/extconf.rb +3 -0
  15. data/features/laser.feature +25 -0
  16. data/features/step_definitions/laser_steps.rb +39 -0
  17. data/features/support/env.rb +14 -0
  18. data/features/support/testdata/1_input +1 -0
  19. data/features/support/testdata/1_output +1 -0
  20. data/features/support/testdata/2_input +4 -0
  21. data/features/support/testdata/2_output +4 -0
  22. data/features/support/testdata/3_input +8 -0
  23. data/features/support/testdata/3_output +11 -0
  24. data/features/support/testdata/4_input +5 -0
  25. data/features/support/testdata/4_output +5 -0
  26. data/features/support/testdata/5_input +13 -0
  27. data/laser.gemspec +382 -0
  28. data/lib/laser.rb +98 -0
  29. data/lib/laser/analysis/annotations.rb +95 -0
  30. data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
  31. data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
  32. data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
  33. data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
  34. data/lib/laser/analysis/argument_expansion.rb +132 -0
  35. data/lib/laser/analysis/arity.rb +34 -0
  36. data/lib/laser/analysis/bindings.rb +144 -0
  37. data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
  38. data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
  39. data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
  40. data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
  41. data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
  42. data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
  43. data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
  44. data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
  45. data/lib/laser/analysis/comments.rb +35 -0
  46. data/lib/laser/analysis/control_flow.rb +28 -0
  47. data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
  48. data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
  49. data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
  50. data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
  51. data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
  52. data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
  53. data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
  54. data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
  55. data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
  56. data/lib/laser/analysis/control_flow/simulation.rb +385 -0
  57. data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
  58. data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
  59. data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
  60. data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
  61. data/lib/laser/analysis/errors.rb +131 -0
  62. data/lib/laser/analysis/laser_utils.rb +18 -0
  63. data/lib/laser/analysis/lexical_analysis.rb +172 -0
  64. data/lib/laser/analysis/method_call.rb +68 -0
  65. data/lib/laser/analysis/protocol_registry.rb +30 -0
  66. data/lib/laser/analysis/scope.rb +118 -0
  67. data/lib/laser/analysis/sexp.rb +159 -0
  68. data/lib/laser/analysis/sexp_analysis.rb +40 -0
  69. data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
  70. data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
  71. data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
  72. data/lib/laser/analysis/signature.rb +76 -0
  73. data/lib/laser/analysis/special_methods/send.rb +67 -0
  74. data/lib/laser/analysis/unused_methods.rb +21 -0
  75. data/lib/laser/analysis/visitor.rb +141 -0
  76. data/lib/laser/annotation_parser/annotations.treetop +126 -0
  77. data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
  78. data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
  79. data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
  80. data/lib/laser/annotation_parser/overload.treetop +24 -0
  81. data/lib/laser/annotation_parser/overload_parser.rb +167 -0
  82. data/lib/laser/annotation_parser/parsers.rb +6 -0
  83. data/lib/laser/annotation_parser/structural.treetop +37 -0
  84. data/lib/laser/annotation_parser/structural_parser.rb +406 -0
  85. data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
  86. data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
  87. data/lib/laser/rake/task.rb +46 -0
  88. data/lib/laser/runner.rb +189 -0
  89. data/lib/laser/scanner.rb +169 -0
  90. data/lib/laser/standard_library/_thread.rb +110 -0
  91. data/lib/laser/standard_library/abbrev.rb +103 -0
  92. data/lib/laser/standard_library/array.rb +418 -0
  93. data/lib/laser/standard_library/base64.rb +91 -0
  94. data/lib/laser/standard_library/basic_object.rb +55 -0
  95. data/lib/laser/standard_library/benchmark.rb +556 -0
  96. data/lib/laser/standard_library/bignum.rb +185 -0
  97. data/lib/laser/standard_library/cgi.rb +275 -0
  98. data/lib/laser/standard_library/cgi/cookie.rb +147 -0
  99. data/lib/laser/standard_library/cgi/core.rb +791 -0
  100. data/lib/laser/standard_library/cgi/html.rb +1021 -0
  101. data/lib/laser/standard_library/cgi/session.rb +537 -0
  102. data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
  103. data/lib/laser/standard_library/cgi/util.rb +188 -0
  104. data/lib/laser/standard_library/class_definitions.rb +333 -0
  105. data/lib/laser/standard_library/comparable.rb +125 -0
  106. data/lib/laser/standard_library/complex.rb +162 -0
  107. data/lib/laser/standard_library/enumerable.rb +178 -0
  108. data/lib/laser/standard_library/exceptions.rb +135 -0
  109. data/lib/laser/standard_library/fixnum.rb +188 -0
  110. data/lib/laser/standard_library/float.rb +180 -0
  111. data/lib/laser/standard_library/hash.rb +237 -0
  112. data/lib/laser/standard_library/integer.rb +123 -0
  113. data/lib/laser/standard_library/laser_magic.rb +7 -0
  114. data/lib/laser/standard_library/nil_false_true.rb +113 -0
  115. data/lib/laser/standard_library/numbers.rb +192 -0
  116. data/lib/laser/standard_library/proc.rb +31 -0
  117. data/lib/laser/standard_library/set.rb +1348 -0
  118. data/lib/laser/standard_library/string.rb +666 -0
  119. data/lib/laser/standard_library/stringio.rb +2 -0
  120. data/lib/laser/standard_library/symbol.rb +125 -0
  121. data/lib/laser/standard_library/tsort.rb +242 -0
  122. data/lib/laser/support/acts_as_struct.rb +66 -0
  123. data/lib/laser/support/frequency.rb +55 -0
  124. data/lib/laser/support/inheritable_attributes.rb +145 -0
  125. data/lib/laser/support/module_extensions.rb +94 -0
  126. data/lib/laser/support/placeholder_object.rb +13 -0
  127. data/lib/laser/third_party/rgl/adjacency.rb +221 -0
  128. data/lib/laser/third_party/rgl/base.rb +228 -0
  129. data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
  130. data/lib/laser/third_party/rgl/condensation.rb +47 -0
  131. data/lib/laser/third_party/rgl/connected_components.rb +138 -0
  132. data/lib/laser/third_party/rgl/control_flow.rb +170 -0
  133. data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
  134. data/lib/laser/third_party/rgl/dominators.rb +124 -0
  135. data/lib/laser/third_party/rgl/dot.rb +93 -0
  136. data/lib/laser/third_party/rgl/graphxml.rb +51 -0
  137. data/lib/laser/third_party/rgl/implicit.rb +174 -0
  138. data/lib/laser/third_party/rgl/mutable.rb +117 -0
  139. data/lib/laser/third_party/rgl/rdot.rb +445 -0
  140. data/lib/laser/third_party/rgl/topsort.rb +72 -0
  141. data/lib/laser/third_party/rgl/transitivity.rb +180 -0
  142. data/lib/laser/third_party/rgl/traversal.rb +348 -0
  143. data/lib/laser/types/types.rb +433 -0
  144. data/lib/laser/version.rb +14 -0
  145. data/lib/laser/warning.rb +149 -0
  146. data/lib/laser/warning_sets/default.yml +13 -0
  147. data/lib/laser/warnings/assignment_in_condition.rb +20 -0
  148. data/lib/laser/warnings/comment_spacing.rb +31 -0
  149. data/lib/laser/warnings/extra_blank_lines.rb +30 -0
  150. data/lib/laser/warnings/extra_whitespace.rb +16 -0
  151. data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
  152. data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
  153. data/lib/laser/warnings/line_length.rb +115 -0
  154. data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
  155. data/lib/laser/warnings/operator_spacing.rb +68 -0
  156. data/lib/laser/warnings/parens_on_declaration.rb +30 -0
  157. data/lib/laser/warnings/rescue_exception.rb +42 -0
  158. data/lib/laser/warnings/semicolon.rb +25 -0
  159. data/lib/laser/warnings/sexp_errors.rb +24 -0
  160. data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
  161. data/lib/laser/warnings/useless_double_quotes.rb +38 -0
  162. data/spec/analysis_specs/annotations_spec.rb +47 -0
  163. data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
  164. data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
  165. data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
  166. data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
  167. data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
  168. data/spec/analysis_specs/bindings_spec.rb +36 -0
  169. data/spec/analysis_specs/comment_spec.rb +93 -0
  170. data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
  171. data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
  172. data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
  173. data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
  174. data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
  175. data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
  176. data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
  177. data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
  178. data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
  179. data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
  180. data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
  181. data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
  182. data/spec/analysis_specs/error_spec.rb +30 -0
  183. data/spec/analysis_specs/laser_class_spec.rb +322 -0
  184. data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
  185. data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
  186. data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
  187. data/spec/analysis_specs/scope_spec.rb +126 -0
  188. data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
  189. data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
  190. data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
  191. data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
  192. data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
  193. data/spec/analysis_specs/sexp_spec.rb +167 -0
  194. data/spec/analysis_specs/spec_helper.rb +27 -0
  195. data/spec/analysis_specs/unused_methods_spec.rb +65 -0
  196. data/spec/analysis_specs/visitor_spec.rb +64 -0
  197. data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
  198. data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
  199. data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
  200. data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
  201. data/spec/annotation_parser_specs/spec_helper.rb +1 -0
  202. data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
  203. data/spec/laser_spec.rb +14 -0
  204. data/spec/rake_specs/spec_helper.rb +1 -0
  205. data/spec/rake_specs/task_spec.rb +67 -0
  206. data/spec/runner_spec.rb +207 -0
  207. data/spec/scanner_spec.rb +75 -0
  208. data/spec/spec_helper.rb +121 -0
  209. data/spec/standard_library/exceptions_spec.rb +19 -0
  210. data/spec/standard_library/globals_spec.rb +14 -0
  211. data/spec/standard_library/set_spec.rb +31 -0
  212. data/spec/standard_library/spec_helper.rb +1 -0
  213. data/spec/standard_library/standard_library_spec.rb +302 -0
  214. data/spec/support_specs/acts_as_struct_spec.rb +94 -0
  215. data/spec/support_specs/frequency_spec.rb +23 -0
  216. data/spec/support_specs/module_extensions_spec.rb +117 -0
  217. data/spec/support_specs/spec_helper.rb +1 -0
  218. data/spec/type_specs/spec_helper.rb +1 -0
  219. data/spec/type_specs/types_spec.rb +133 -0
  220. data/spec/warning_spec.rb +95 -0
  221. data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
  222. data/spec/warning_specs/comment_spacing_spec.rb +65 -0
  223. data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
  224. data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
  225. data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
  226. data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
  227. data/spec/warning_specs/line_length_spec.rb +173 -0
  228. data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
  229. data/spec/warning_specs/operator_spacing_spec.rb +104 -0
  230. data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
  231. data/spec/warning_specs/rescue_exception_spec.rb +105 -0
  232. data/spec/warning_specs/semicolon_spec.rb +58 -0
  233. data/spec/warning_specs/spec_helper.rb +1 -0
  234. data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
  235. data/status_reports/2010/12/2010-12-14.md +163 -0
  236. data/status_reports/2010/12/2010-12-23.md +298 -0
  237. data/status_reports/2010/12/2010-12-24.md +6 -0
  238. data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
  239. data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
  240. data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
  241. data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
  242. data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
  243. data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
  244. data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
  245. data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
  246. data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
  247. data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
  248. data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
  249. data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
  250. data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
  251. data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
  252. data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
  253. data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
  254. data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
  255. data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
  256. data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
  257. data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
  258. data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
  259. data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
  260. data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
  261. data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
  262. data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
  263. data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
  264. data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
  265. data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
  266. data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
  267. data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
  268. data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
  269. data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
  270. data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
  271. data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
  272. data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
  273. data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
  274. data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
  275. data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
  276. data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
  277. data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
  278. data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
  279. data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
  280. data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
  281. data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
  282. data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
  283. data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
  284. data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
  285. data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
  286. data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
  287. data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
  288. data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
  289. data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
  290. data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
  291. data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
  292. data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
  293. data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
  294. data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
  295. data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
  296. data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
  297. data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
  298. data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
  299. data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
  300. data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
  301. data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
  302. data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
  303. data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
  304. data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
  305. data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
  306. data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
  307. data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
  308. data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
  309. data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
  310. data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
  311. data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
  312. data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
  313. data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
  314. data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
  315. data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
  316. data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
  317. data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
  318. data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
  319. metadata +470 -0
@@ -0,0 +1,94 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe ActsAsStruct do
4
+ members = :first, :second, :third, :fourth, :fifth
5
+ values = 1, 2, 3, 4, 5
6
+ zipped = members.zip(values)
7
+ derived_members = members + [:sixth, :seventh]
8
+ derived_values = values + [6, 7]
9
+ derived_zipped = derived_members.zip(derived_values)
10
+
11
+ before do
12
+ @class = Class.new do
13
+ extend ActsAsStruct
14
+ acts_as_struct *members
15
+ end
16
+ @instance = @class.new(*values)
17
+ @derived_class = Class.new(@class) do
18
+ acts_as_struct(*(derived_members - members))
19
+ end
20
+ @derived_instance = @derived_class.new(*derived_values)
21
+ end
22
+
23
+ describe '#acts_as_struct' do
24
+ it 'creates readers for all named attributes' do
25
+ members.each { |member| @instance.should respond_to(member) }
26
+ end
27
+
28
+ it 'creates writers for all named attributes' do
29
+ members.each { |member| @instance.should respond_to("#{member}=") }
30
+ end
31
+
32
+ describe '#initialize' do
33
+ it 'allows initialization via positional arguments' do
34
+ zipped.each { |member, value| @instance.send(member).should == value }
35
+ end
36
+
37
+ it 'allows initialization with a hash' do
38
+ instance = @class.new(Hash[zipped.flatten])
39
+ zipped.each { |member, value| @instance.send(member).should == value }
40
+ end
41
+
42
+ it 'allows fewer positional arguments than the maximum' do
43
+ instance = @class.new(1)
44
+ instance.first.should == 1
45
+ instance.third.should == nil
46
+ end
47
+
48
+ it 'raises on too many positional arguments' do
49
+ expect { @class.new(1,2,3,4,5,6) }.to raise_error(ArgumentError)
50
+ end
51
+ end
52
+
53
+ describe '#keys' do
54
+ it 'returns the keys used in acts_as_struct' do
55
+ @instance.keys.should == members
56
+ end
57
+ end
58
+
59
+ describe '#values' do
60
+ it 'returns the values in the same order as used in acts_as_struct' do
61
+ @instance.values.should == values
62
+ end
63
+ end
64
+
65
+ describe '#keys_and_values' do
66
+ it 'returns the keys and values arrays zipped' do
67
+ @instance.keys_and_values.should == zipped
68
+ end
69
+ end
70
+
71
+ describe '#each' do
72
+ it 'yields each key and value in order' do
73
+ yielded_values = []
74
+ @instance.each { |k, v| yielded_values << [k, v] }
75
+ yielded_values.should == zipped
76
+ end
77
+ end
78
+
79
+ describe '#<=>' do
80
+ it 'compares the values pairwise, in the order given by the acts_as_struct call' do
81
+ @class.new(1,2,3).should be < @class.new(2,2,3)
82
+ @class.new(1,2,3).should be < @class.new(1,2,4)
83
+ @class.new(1,2,3).should be == @class.new(1,2,3)
84
+ @class.new(4,4,5).should be > @class.new(4,4,4)
85
+ end
86
+ end
87
+
88
+ describe 'when used in a derived class that is also using acts_as_struct' do
89
+ it 'should simply append the new members to create a compatible subtype' do
90
+ @derived_instance.keys_and_values.should == derived_zipped
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Frequency do
4
+ describe Frequency::NEVER do
5
+ it { Frequency::NEVER.should be == Frequency::NEVER }
6
+ it { Frequency::NEVER.should be < Frequency::MAYBE }
7
+ it { Frequency::NEVER.should be < Frequency::ALWAYS }
8
+ end
9
+
10
+ describe Frequency::MAYBE do
11
+ it { Frequency::MAYBE.should be > Frequency::NEVER }
12
+ it { Frequency::MAYBE.should be == Frequency::MAYBE }
13
+ it { Frequency::MAYBE.should be < Frequency::ALWAYS }
14
+ end
15
+
16
+ describe Frequency::ALWAYS do
17
+ it { Frequency::ALWAYS.should be > Frequency::NEVER }
18
+ it { Frequency::ALWAYS.should be > Frequency::MAYBE }
19
+ it { Frequency::ALWAYS.should be == Frequency::ALWAYS }
20
+ end
21
+
22
+ it { Frequency.should_not respond_to(:new) }
23
+ end
@@ -0,0 +1,117 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe ModuleExtensions do
4
+ before do
5
+ @class = Class.new do
6
+ extend ModuleExtensions
7
+ attr_accessor_with_default :acc, {a: 2}
8
+ cattr_reader :read1, :read2
9
+ cattr_writer :write1, :write2
10
+ cattr_accessor :both1, :both2
11
+ cattr_accessor_with_default :arr1, []
12
+ def even?(x)
13
+ x % 2 == 0
14
+ end
15
+ opposite_method :odd?, :even?
16
+ end
17
+ end
18
+
19
+ describe 'attr_accessor_with_default' do
20
+ it 'creates an reader that defaults to the provided value' do
21
+ @class.new.acc.should == {a: 2}
22
+ end
23
+
24
+ it 'creates a writer that causes the default to be lost forever' do
25
+ x = @class.new
26
+ x.acc = {b: 3}
27
+ x.acc.should == {b: 3}
28
+ end
29
+ end
30
+
31
+ describe '#cattr_reader' do
32
+ it 'creates reading methods for the given variables' do
33
+ @class.__send__(:instance_variable_set, :@read1, 'hello')
34
+ @class.read1.should == 'hello'
35
+ @class.__send__(:instance_variable_set, :@read2, 5)
36
+ @class.read2.should == 5
37
+ end
38
+ end
39
+
40
+ describe '#cattr_writer' do
41
+ it 'creates writing methods for the given variables' do
42
+ @class.write1 = 'hello'
43
+ @class.__send__(:instance_variable_get, :@write1).should == 'hello'
44
+ @class.write2 = 5
45
+ @class.__send__(:instance_variable_get, :@write2).should == 5
46
+ end
47
+ end
48
+
49
+ describe '#cattr_accessor' do
50
+ it 'creates reading and writing methods for the given variables' do
51
+ @class.both1 = 'hello'
52
+ @class.both1.should == 'hello'
53
+ @class.__send__(:instance_variable_get, :@both1).should == 'hello'
54
+ @class.__send__(:instance_variable_set, :@both1, 'world')
55
+ @class.both1.should == 'world'
56
+ @class.both2 = 5
57
+ @class.both2.should == 5
58
+ @class.__send__(:instance_variable_get, :@both2).should == 5
59
+ @class.__send__(:instance_variable_set, :@both2, 10)
60
+ @class.both2.should == 10
61
+ end
62
+ end
63
+
64
+ describe '#cattr_accessor_with_default' do
65
+ it 'creates reading and writing methods, but defaults the ivar value' do
66
+ @class.arr1.should == []
67
+ @class.__send__(:instance_variable_get, :@arr1).should == []
68
+ @class.arr1.should == [] # second invocation, after default value set
69
+ @class.arr1 = [1, 2]
70
+ @class.arr1.should == [1, 2]
71
+ @class.__send__(:instance_variable_get, :@arr1).should == [1, 2]
72
+ end
73
+ end
74
+
75
+ describe '#cattr_get_and_setter' do
76
+ before do
77
+ @base = Class.new do
78
+ extend ModuleExtensions
79
+ cattr_get_and_setter :type
80
+ type :silly
81
+ end
82
+ end
83
+
84
+ it 'acts a setter and getter on the base class' do
85
+ @base.type.should == :silly
86
+ end
87
+
88
+ it 'is not inherited' do
89
+ @derived = Class.new(@base)
90
+ @derived.type.should_not == :silly
91
+ end
92
+
93
+ it 'can be used by inherited classes' do
94
+ @derived = Class.new(@base) do
95
+ type :laughable
96
+ end
97
+ @derived.type.should == :laughable
98
+ @base.type.should == :silly
99
+ end
100
+
101
+ it 'turns a block into a proc and sets it' do
102
+ @derived = Class.new(@base) do
103
+ type { 5 + 3 }
104
+ end
105
+ @derived.type.call.should == 8
106
+ end
107
+ end
108
+
109
+ describe '#opposite_method' do
110
+ it 'creates a new method that is the opposite of the specified method' do
111
+ @class.new.even?(4).should be true
112
+ @class.new.odd?(4).should be false
113
+ @class.new.even?(1).should be false
114
+ @class.new.odd?(1).should be true
115
+ end
116
+ end
117
+ end
@@ -0,0 +1 @@
1
+ require_relative '../spec_helper'
@@ -0,0 +1 @@
1
+ require_relative '../spec_helper'
@@ -0,0 +1,133 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Types do
4
+ describe '.subtype?' do
5
+ describe 'invariant class types' do
6
+ it 'should include itself' do
7
+ Types.subtype?(Types::ClassType.new('Integer', :invariant),
8
+ Types::ClassType.new('Integer', :invariant)).should be true
9
+ end
10
+
11
+ it 'should not include subclasses' do
12
+ Types.subtype?(Types::ClassType.new('Fixnum', :invariant),
13
+ Types::ClassType.new('Integer', :invariant)).should be false
14
+ end
15
+
16
+ it 'should not include superclasses' do
17
+ Types.subtype?(Types::ClassType.new('Numeric', :invariant),
18
+ Types::ClassType.new('Integer', :invariant)).should be false
19
+ end
20
+ end
21
+
22
+ describe 'covariant class types' do
23
+ it 'should include itself' do
24
+ Types.subtype?(Types::ClassType.new('Integer', :invariant),
25
+ Types::ClassType.new('Integer', :covariant)).should be true
26
+ end
27
+
28
+ it 'should include subclasses' do
29
+ Types.subtype?(Types::ClassType.new('Fixnum', :invariant),
30
+ Types::ClassType.new('Integer', :covariant)).should be true
31
+ end
32
+
33
+ it 'should not include superclasses' do
34
+ Types.subtype?(Types::ClassType.new('Numeric', :invariant),
35
+ Types::ClassType.new('Integer', :covariant)).should be false
36
+ end
37
+
38
+ it 'should include a union of subclasses' do
39
+ Types.subtype?(Types::UnionType.new(
40
+ [Types::ClassType.new('Integer', :invariant),
41
+ Types::ClassType.new('Float', :invariant)]),
42
+ Types::ClassType.new('Numeric', :covariant)).should be true
43
+ end
44
+ end
45
+
46
+ describe 'contravariant class types' do
47
+ it 'should include itself' do
48
+ Types.subtype?(Types::ClassType.new('Integer', :invariant),
49
+ Types::ClassType.new('Integer', :contravariant)).should be true
50
+ end
51
+
52
+ it 'should not include subclasses' do
53
+ Types.subtype?(Types::ClassType.new('Fixnum', :invariant),
54
+ Types::ClassType.new('Integer', :contravariant)).should be false
55
+ end
56
+
57
+ it 'should include superclasses' do
58
+ Types.subtype?(Types::ClassType.new('Numeric', :invariant),
59
+ Types::ClassType.new('Integer', :contravariant)).should be true
60
+ end
61
+ end
62
+
63
+ describe 'union types' do
64
+ it 'should include member types' do
65
+ Types.subtype?(Types::ClassType.new('Integer', :invariant),
66
+ Types::UnionType.new(
67
+ [Types::ClassType.new('Integer', :invariant),
68
+ Types::ClassType.new('String', :invariant)])).should be true
69
+ end
70
+ end
71
+ end
72
+ describe Types::TOP do
73
+ it 'should be equal to a covariant BasicObject instance' do
74
+ Types::TOP.should == Types::ClassType.new('BasicObject', :covariant)
75
+ end
76
+ end
77
+
78
+ describe Types::UnionType do
79
+ it 'should compare equal despite member type ordering' do
80
+ Types::UnionType.new([Types::STRING, Types::FIXNUM, Types::ARRAY]).should ==
81
+ Types::UnionType.new([Types::ARRAY, Types::STRING, Types::FIXNUM])
82
+ end
83
+ end
84
+
85
+ describe Types::ClassType do
86
+ describe '#possible_classes' do
87
+ it 'should find subclasses if the ClassType is covariant and is a Class' do
88
+ Types::ClassType.new('Integer', :covariant).possible_classes.should be_superset(
89
+ ::Set[ClassRegistry['Integer'], ClassRegistry['Fixnum'], ClassRegistry['Bignum']])
90
+ end
91
+
92
+ it 'should find the exact class ClassType is invariant and is a Class' do
93
+ Types::ClassType.new('Integer', :invariant).possible_classes.should ==
94
+ ::Set[ClassRegistry['Integer']]
95
+ end
96
+
97
+ it 'should find superclasses if the ClassType is invariant and is a Class' do
98
+ Types::ClassType.new('Fixnum', :contravariant).possible_classes.should ==
99
+ ::Set[ClassRegistry['Fixnum'], ClassRegistry['Integer'], ClassRegistry['Numeric'],
100
+ ClassRegistry['Object'], ClassRegistry['BasicObject']]
101
+ end
102
+
103
+ it 'should find classes including the module if the ClassType is covariant and is a Module' do
104
+ Types::ClassType.new('Kernel', :covariant).possible_classes.should ==
105
+ ::Set.new(ClassRegistry['Object'].subset)
106
+ comparables = Types::ClassType.new('Comparable', :covariant).possible_classes
107
+ %w(String Numeric Integer Fixnum Bignum Float).each do |comparable|
108
+ comparables.should include(ClassRegistry[comparable])
109
+ end
110
+ end
111
+ end
112
+
113
+ describe '#matching_methods' do
114
+ it 'should search the possible classes for instance methods of the same name (covariant)' do
115
+ Types::ClassType.new('Integer', :covariant).matching_methods('modulo').should ==
116
+ [ClassRegistry['Numeric'].instance_method(:modulo),
117
+ ClassRegistry['Fixnum'].instance_method(:modulo),
118
+ ClassRegistry['Bignum'].instance_method(:modulo)]
119
+ end
120
+
121
+ it 'should search the possible classes for instance methods of the same name (invariant)' do
122
+ Types::ClassType.new('Integer', :invariant).matching_methods('odd?').should ==
123
+ [ClassRegistry['Integer'].instance_method(:odd?)]
124
+ end
125
+
126
+ it 'should search the possible classes for instance methods of the same name (contravariant)' do
127
+ Types::ClassType.new('Bignum', :contravariant).matching_methods('odd?').should ==
128
+ [ClassRegistry['Bignum'].instance_method(:odd?),
129
+ ClassRegistry['Integer'].instance_method(:odd?)]
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,95 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Warning do
4
+ describe 'when subclassed' do
5
+ it 'registers the new class in all_warnings' do
6
+ klass = Class.new(Warning)
7
+ Warning.all_warnings.should include(klass)
8
+ end
9
+ end
10
+
11
+ it 'does not match anything' do
12
+ Warning.should_not warn('hello(world)')
13
+ Warning.should_not warn(' a +b ')
14
+ end
15
+
16
+ describe 'short names in warnings' do
17
+ before do
18
+ @real_warnings = Warning.all_warnings.select do |x|
19
+ x.name && x != Warning && x != FileWarning && x != LineWarning
20
+ end
21
+ end
22
+
23
+ it 'exist for every warning class' do
24
+ @real_warnings.select {|x| x.name && x.short_name == nil}.should be_empty
25
+ end
26
+
27
+ it 'do not conflict with each other' do
28
+ short_names = @real_warnings.map {|x| x.short_name}.uniq
29
+ short_names.size.should == @real_warnings.size
30
+ end
31
+ end
32
+
33
+ it 'does not change lines when it fixes them' do
34
+ Warning.should correct_to('a+b', 'a+b')
35
+ Warning.should correct_to(' b ** c+1 eval(string) ', ' b ** c+1 eval(string) ')
36
+ end
37
+
38
+ describe '#concrete_warnings' do
39
+ before { @concrete = Warning.concrete_warnings }
40
+ it 'returns a list of classes that are subclasses of Warning' do
41
+ @concrete.should_not be_empty
42
+ @concrete.each {|w| w.ancestors.should include(Warning) }
43
+ end
44
+
45
+ it 'returns a list that does not contain Warning, FileWarning, or LineWarning' do
46
+ @concrete.should_not include(Warning)
47
+ @concrete.should_not include(FileWarning)
48
+ @concrete.should_not include(LineWarning)
49
+ end
50
+ end
51
+
52
+ describe '#desc' do
53
+ it "defaults to the class's name with all info" do
54
+ warning = Warning.new('hello.rb', 'a+b')
55
+ warning.severity = 7
56
+ warning.line_number = 3
57
+ warning.desc.should == 'Laser::Warning hello.rb:3 (7)'
58
+ end
59
+
60
+ it 'when specified in a subclass as a string, just uses the string' do
61
+ subclass = Class.new(Warning) { desc 'hello' }
62
+ subclass.new('a', 'b').desc.should == 'hello'
63
+ end
64
+
65
+ it 'when specified in a subclass as a block, runs that proc as the instance' do
66
+ subclass = Class.new(Warning) do
67
+ severity 1024
68
+ desc { self.class.severity.to_s }
69
+ end
70
+ subclass.new('a', 'b').desc.should == '1024'
71
+ end
72
+ end
73
+
74
+ describe '#type' do
75
+ it 'returns the current type when no args are provided' do
76
+ klass = Class.new(Warning) do
77
+ def self.set_type
78
+ @type = 'hai'
79
+ end
80
+ end
81
+ klass.set_type
82
+ klass.type.should == 'hai'
83
+ end
84
+
85
+ it 'sets the type when an argument is provided' do
86
+ klass = Class.new(Warning) { type :silly }
87
+ klass.type.should == 'silly'
88
+ end
89
+
90
+ it 'sets a short name based on the type provided' do
91
+ klass = Class.new(Warning) { type :silly }
92
+ klass.short_name.should =~ /SI\d/
93
+ end
94
+ end
95
+ end