empty: src: "" tem: "" numbers: src: "id > 45 and (3 > -id or 3+3)" tem: "((node.zip>45) and ((3>-node.zip) or (3+3)))" global_method: src: "now.strftime('%Y')" tem: "Time.now.strftime(\"%Y\")" dynamic_string: src: "now.strftime(\"#{name}\")" tem: "Time.now.strftime(\"#{node.name}\")" dynamic_string_again: src: "now.strftime(\"#{name}\")" tem: "Time.now.strftime(\"#{node.name}\")" symbol: src: ":foobar" sxp: 's(:lit, :foobar)' rewrite_variables: src: "!prev.ancestor?(main) && !node.ancestor?(main)" tem: "(not previous.ancestor?(@node) and not node.ancestor?(@node))" method_can_return_nil: src: "spouse.name" tem: "(node.spouse ? node.spouse.name : nil)" method_on_method_can_return_nil: src: "spouse.name == 'yo'" tem: "(node.spouse ? (node.spouse.name==\"yo\") : nil)" res: "" nil_greater_then: src: "spouse.id > 1" tem: "(node.spouse ? (node.spouse.zip>1) : nil)" nil_ternary_op: src: "spouse ? 'foo' : 'bar'" tem: "node.spouse ? \"foo\" : \"bar\"" res: 'bar' nested_ternary_op: src: "spouse.name == 'Adam' ? 'man' : 'not a man'" tem: "(node.spouse ? (node.spouse.name==\"Adam\") : nil) ? \"man\" : \"not a man\"" res: "not a man" method_on_method: src: "project.name.to_s" tem: "node.project.name.to_s" res: 'project' comp_ternary_op: src: "1 > 2 ? 'foo' : 'bar'" tem: "(1>2) ? \"foo\" : \"bar\"" res: "bar" method_ternary_op: src: "id > 2 ? 'foo' : 'bar'" tem: "(node.zip>2) ? \"foo\" : \"bar\"" res: "foo" method_argument_can_be_nil: src: "vowel_count(spouse.name)" tem: "(node.spouse ? vowel_count(node.spouse.name) : nil)" multi_arg_method_argument_can_be_nil: src: "log_info(spouse, 'foobar')" tem: "(node.spouse ? log_info(node.spouse, \"foobar\") : nil)" multi_arg_method_arguments_can_be_nil: src: "log_info(husband, spouse.name)" tem: "((node.husband && node.spouse) ? log_info(node.husband, node.spouse.name) : nil)" multi_arg_method_arguments_can_be_nil_same_condition: src: "log_info(spouse, spouse.name)" tem: "(node.spouse ? log_info(node.spouse, node.spouse.name) : nil)" literal_argument_for_method: src: "vowel_count('ruby')" res: "2" safe_method_defined_as_symbol: src: "foo" tem: "contextual_foo" optional_arguments: src: "width(:mode => 'pv')" tem: "node.width({:mode => \"pv\"})" res: "mode: pv, type: none" optional_arguments: src: "width" tem: "node.width" res: "mode: none, type: none" optional_arguments_string: src: "width('nice' => 1 == 1)" tem: "node.width({\"nice\" => (1==1)})" res: "nice!" module_method: src: "maze" tem: "node.mazette" res: "Mazette !" regexp: src: "maze.gsub(/ette/,'o')" tem: "node.mazette.gsub(/ette/, \"o\")" res: "Mazo !" instance_variable: src: "@foo.maze" tem: "node.mazette" res: "Mazette !" prepend_one: src: "prepend_one(4) + prepend_one" tem: "(add(10, 4)+add(10))" res: "24" prepend_many: src: "prepend_many(4) + prepend_many" tem: "(add(10, 20, 4)+add(10, 20))" res: "64" append_one: src: "append_one(4) + append_one" tem: "(add(4, 10)+add(10))" res: "24" append_many: src: "append_many(4) + append_many" tem: "(add(4, 10, 20)+add(10, 20))" res: "64" safe_property: src: "dog_name" tem: "node.prop['dog_name']" res: "Biscotte" match_on_subclass: src: "log_info(sub, 'hello')" tem: "log_info(sub, \"hello\")" optional_argument_subclass: src: "width(:mode => str)" tem: "node.width({:mode => str})" simple_accept_nil: src: "accept_nil(dictionary[:foo])" tem: "accept_nil(get_dict[:foo])" accept_nil_many_arguments: src: "accept_nil(dictionary[:foo], dictionary[:bar])" tem: "accept_nil(get_dict[:foo], get_dict[:bar])" res: "[\"Foo\", nil]" accept_nil_many_arguments_no_all_nil: src: "accept_nil('hop', dictionary[:bar])" tem: "accept_nil(\"hop\", get_dict[:bar])" res: "[\"hop\", nil]" no_nil_in_accept_nil: src: "accept_nil(no_nil(dictionary[:foo]))" tem: "accept_nil((get_dict[:foo] ? no_nil(get_dict[:foo]) : nil))" res: "[\"Foo\", nil]" two_no_nil_in_accept_nil: src: "accept_nil(no_nil(dictionary[:foo]), no_nil(dictionary[:bar]))" tem: "accept_nil((get_dict[:foo] ? no_nil(get_dict[:foo]) : nil), (get_dict[:bar] ? no_nil(get_dict[:bar]) : nil))" res: "[\"Foo\", nil]" accept_nil_in_no_nil: src: "no_nil(accept_nil(dictionary[:foo]))" tem: "no_nil(accept_nil(get_dict[:foo]))" noop_method: src: 'no_op("hello")' tem: '("hello")' res: 'hello' noop_other_signature: src: 'no_op(45)' tem: 'transform(45)' build_finder: # This test shows a way to 'pre_process' literal content with a helper method that should return a TypedString src: 'find("one two")' tem: 'secure(Node) { Node.find("one two") }' methods_on_nil: src: 'dictionary[:foo].blank?' tem: 'get_dict[:foo].blank?' equality_on_nil: src: 'dictionary[:foo] == "yo"' tem: '(get_dict[:foo]=="yo")' or_same_class: src: "vowel_count(dictionary[:bar] || 'aeiou')" tem: 'vowel_count((get_dict[:bar] or "aeiou"))' res: '5' class: src: "@foo.kind_of?(Page)" tem: "node.kind_of?(Page)" class_map_as_string: src: "@foo.kind_of?(Document)" tem: "node.is_like?(\"DOC\")" proc_to_resolve_class: src: "author" tem: "node.author" method_on_array: src: "@foo.genitors.size" tem: "node.genitors.size" method_on_array_with_nil: src: "@foo.children.size" tem: "(node.children ? node.children.size : nil)" map_allowed_method: src: "%w{45 52}.map(:to_i)" tem: "[\"45\",\"52\"].map(&:to_i).compact" res: "4552" map_forbidden_method: src: "%w{45 52}.map(:foo)" tem: "unknown method 'map(:foo)' for '[\"45\",\"52\"]' of type [String]." eval_true: src: "true" tem: "true" eval_false: src: "false" tem: "false" number_array: src: "[3, 6]" tem: '[3,6]' string_array: src: "%w{foo bar}.join(',')" res: 'foo,bar' array_bad_method: src: "%w{foo bar}.plop(',')" res: "unknown method 'plop(String)' for '[\"foo\",\"bar\"]' of type [String]."