char *test_implicit_method_call_no_parens() { spec_describe("implicit method no parens: print 'word'"); FxP_ParserContext *context = parse_string("print 'word'\n"); setup_json(); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get(expression, "method_call"), "message"), "lookup"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "print", "message correct"); element = json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get(expression, "method_call"), "arguments"), 0), "literal"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "word", "arguments correct"); cleanup(); return NULL; }
char *test_fxb_array_pop() { spec_describe("Push until expansion required"); FxB_Array *array = FxB_Array_create(32); fxb_array_push(array, "1"); fxb_array_push(array, "2"); fxb_array_push(array, "3"); char *value = fxb_array_pop(array); assert_strings_equal(value, "3", "last value"); assert_ints_equal(fxb_array_length(array), 2, "length"); value = fxb_array_pop(array); assert_strings_equal(value, "2", "middle value"); assert_ints_equal(fxb_array_length(array), 1, "length"); value = fxb_array_pop(array); assert_strings_equal(value, "1", "first value"); assert_ints_equal(fxb_array_length(array), 0, "length"); fxb_array_free(array); return NULL; }
char *test_import_with_parens() { spec_describe("import expression: import('my-file')"); FxP_ParserContext *context = parse_string("import('my-file')"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"import\": {\n" " \"path\": {\n" " \"literal\": {\n" " \"bit\": {\n" " \"STRING\": \"my-file\"\n" " },\n" " \"class\": \"String\"\n" " }\n" " }\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_fxb_array_set_at_index() { spec_describe("set at index, set at index above capacity"); FxB_Array *array = FxB_Array_create(32); fxb_array_set(array, 1, "Gerbil"); assert_ints_equal(fxb_array_length(array), 2, "length after setting index 1"); assert_strings_equal((char *)(fxb_array_get(array, 1)), "Gerbil", "value at index 1"); fxb_array_set(array, 32, "Another Gerbil"); assert_ints_equal(fxb_array_capacity(array), 128, "capacity after setting above current capacity"); assert_ints_equal(fxb_array_length(array), 33, "length"); assert_strings_equal((char *)(fxb_array_get(array, 32)), "Another Gerbil", "value"); fxb_array_free(array); return NULL; }
char *test_block_assignment() { spec_describe("function assignments: ?: -> { !empty? }"); FxP_ParserContext *context = parse_string("?: -> { !empty? }\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"colon_expression\": {\n" " \"left\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"?\"\n" " }\n" " }\n" " },\n" " \"right\": {\n" " \"function_definition\": {\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"empty?\"\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"!\"\n" " }\n" " }\n" " }\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_fxb_array_push_multiple_times() { spec_describe("Push many times"); FxB_Array *array = FxB_Array_create(32); fxb_array_push(array, "Gerbil"); fxb_array_push(array, "Fish"); fxb_array_push(array, "Human"); assert_ints_equal(fxb_array_length(array), 3, "length"); assert_ints_equal(fxb_array_capacity(array), 32, "capacity"); assert_strings_equal((char *)(fxb_array_at_index(array, 0)), "Gerbil", "value at index 0"); assert_strings_equal((char *)(fxb_array_at_index(array, 1)), "Fish", "value at index 1"); assert_strings_equal((char *)(fxb_array_at_index(array, 2)), "Human", "value at index 2"); fxb_array_free(array); return NULL; }
// this test ensures that HTML inside of the content is escaped correctly. void run_escape_test() { // what the node's to string should be equal to const std::string htmlString = "<a class=\"button\"><script>alert(\"ha ha hacked!\")</script></a>"; CTML::Node node("a.button", "<script>alert(\"ha ha hacked!\")</script>"); // the node's string output const std::string nodeString = node.ToString(CTML::SINGLE_LINE, 0); bool test = assert_strings_equal(htmlString, nodeString); std::cout << "Escape Test " << ((test) ? "passed!" : "failed!") << std::endl << "HTML Output: " << nodeString << std::endl << // use a double end line at the end for spacing between tests "Expected Output: " << htmlString << std::endl << std::endl; }
// this test checks if the classes provided are correctly stored void run_class_test() { const std::string classString = "test classes are fun"; CTML::Node testNode("a#test.test.classes.are.fun"); std::cout << testNode.GetAttribute("hehhehtest") << std::endl; // get the test node's classlist. const std::string classList = testNode.GetAttribute("class"); bool test = assert_strings_equal(classString, classList); std::cout << "Class Test " << ((test) ? "passed!" : "failed!") << std::endl << "Class Output: " << classList << std::endl << // use a double end line at the end for spacing between tests "Expected Output: " << classString << std::endl << std::endl; }
// this test ensures that the HTML document created is equal to a correct HTML5 document void run_document_test() { // what the document's to string should be equal to const std::string htmlString = "<!DOCTYPE html><html><head></head><body><h1><test!></h1></body></html>"; CTML::Document doc; // the string output of the document doc.AddNodeToBody(CTML::Node("h1", "<test!>")); const std::string docString = doc.ToString(CTML::SINGLE_LINE); bool test = assert_strings_equal(htmlString, docString); std::cout << "Document Test " << ((test) ? "passed!" : "failed!") << std::endl << "HTML Output: " << docString << std::endl << // use a double end line at the end for spacing between tests "Expected Output: " << htmlString << std::endl << std::endl; }
char *test_fxb_array_push() { spec_describe("Push"); FxB_Array *array = FxB_Array_create(32); fxb_array_push(array, "Gerbil"); assert_ints_equal(fxb_array_length(array), 1, "length"); assert_strings_equal((char *)(fxb_array_at_index(array, 0)), "Gerbil", "value"); fxb_array_free(array); return NULL; }
char *test_native_with_args() { spec_describe("native assignments: native('fxi_native_to_s', format: String)"); FxP_ParserContext *context = parse_string("native('fxi_native_to_s', format: String)\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"native\": {\n" " \"function_name\": {\n" " \"literal\": {\n" " \"bit\": {\n" " \"STRING\": \"fxi_native_to_s\"\n" " },\n" " \"class\": \"String\"\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"colon_expression\": {\n" " \"left\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"format\"\n" " }\n" " }\n" " },\n" " \"right\": {\n" " \"lookup\": {\n" " \"type\": \"Class Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"String\"\n" " }\n" " }\n" " }\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_fxb_array_push_until_expansion() { spec_describe("Push until expansion required"); FxB_Array *array = FxB_Array_create(32); int i; char *num; for (i = 0; i < 33; i++) { num = calloc(4, sizeof(char)); sprintf(num, "%d", i); fxb_array_push(array, num); } assert_ints_equal(fxb_array_length(array), 33, "length"); assert_ints_equal(fxb_array_capacity(array), 128, "capacity"); assert_strings_equal((char *)(fxb_array_at_index(array, 1)), "1", "value at index 1"); assert_strings_equal((char *)(fxb_array_at_index(array, 30)), "30", "value at index 30"); assert_strings_equal((char *)(fxb_array_at_index(array, 32)), "32", "value at index 32"); fxb_array_r_free(array); return NULL; }
char *test_no_parens_method_call() { spec_describe("method: Print.line 'word' "); FxP_ParserContext *context = parse_string("Print.line 'word' \n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"lookup\": {\n" " \"type\": \"Class Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"Print\"\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"line\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"STRING\": \"word\"\n" " },\n" " \"class\": \"String\"\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_operator_method_call() { spec_describe("opreator expression: 1 + 1"); FxP_ParserContext *context = parse_string("1 + 1\n"); setup_json(); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get(expression, "method_call"), "receiver"), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "receiver correct"); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get(expression, "method_call"), "message"), "lookup"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "+", "message correct"); element = json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get(expression, "method_call"), "arguments"), 0), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "arguments correct"); cleanup(); return NULL; }
char *test_empty_function_with_line_end() { spec_describe("empty function: -> {\n}"); FxP_ParserContext *context = parse_string("-> {\n}\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"function_definition\": {\n" " \"expressions\": []\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_parse_from_file() { spec_describe("parsing content of file, should work the same"); FxP_ParserContext *context = parse_file("spec/c-unit/interpreter/fixtures/import-test.fx"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"colon_expression\": {\n" " \"left\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"it-worked?\"\n" " }\n" " }\n" " },\n" " \"right\": {\n" " \"literal\": {\n" " \"bit\": {\n" " \"STRING\": \"true\"\n" " },\n" " \"class\": \"Boolean\"\n" " }\n" " }\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_expression_function_with_expression_expression() { spec_describe("expression function sandwich: 1 + 1\n-> {\n print 'word'\n}\n2 * 2"); FxP_ParserContext *context = parse_string("1 + 1\n-> {\n print 'word'\n}\n2 * 2\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 1\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"+\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 1\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " }\n" " ]\n" " }\n" " },\n" " {\n" " \"function_definition\": {\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"print\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"STRING\": \"word\"\n" " },\n" " \"class\": \"String\"\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" " }\n" " },\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 2\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"*\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 2\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_multi_line_method_call() { spec_describe("multiline method call: (n / 10)\n\t.truncate"); FxP_ParserContext *context = parse_string("(n / 10)\n\t.truncate\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"grouped_expression\": {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"n\"\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"/\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 10\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"truncate\"\n" " }\n" " }\n" " }\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); spec_describe("multiline method call: (n / 10).\n\ttruncate"); context = parse_string("(n / 10).\n\ntruncate\n"); inspection = fxp_parser_inspect(context); assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_two_expressions() { spec_describe("test order of two expressions: 1 + 1\nprint 'word'"); FxP_ParserContext *context = parse_string("1 + 1\nprint 'word'"); setup_json(); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get(expression, "method_call"), "receiver"), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "first expression receiver correct"); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get(expression, "method_call"), "message"), "lookup"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "+", "second expression message correct"); element = json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get(expression, "method_call"), "arguments"), 0), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "second expression arguments correct"); expression = json_array_get(expressions, 1); \ element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get(expression, "method_call"), "message"), "lookup"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "print", "first expression message correct"); element = json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get(expression, "method_call"), "arguments"), 0), "literal"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "word", "first expression arguments correct"); cleanup(); return NULL; }
char *test_function_assignment() { spec_describe("attr assignment with function def: convert: -> (n: 11) { 'eleven' }"); FxP_ParserContext *context = parse_string("convert: -> (n: 11) { 'eleven' }\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"colon_expression\": {\n" " \"left\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"convert\"\n" " }\n" " }\n" " },\n" " \"right\": {\n" " \"function_definition\": {\n" " \"arguments\": {\n" " \"function_arguments\": [\n" " {\n" " \"colon_expression\": {\n" " \"left\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"n\"\n" " }\n" " }\n" " },\n" " \"right\": {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 11\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " }\n" " }\n" " }\n" " ]\n" " },\n" " \"expressions\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"STRING\": \"eleven\"\n" " },\n" " \"class\": \"String\"\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_multi_operator_method() { spec_describe("multi operator method chain: 1 + (n * 3) - 5"); FxP_ParserContext *context = parse_string("1 + (n * 3) - 5\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 1\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"+\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"grouped_expression\": {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"n\"\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"*\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 3\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"-\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"literal\": {\n" " \"bit\": {\n" " \"INTEGER\": 5\n" " },\n" " \"class\": \"Integer\"\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_method_call_with_block() { spec_describe("method with block: collection.map -> (e) { Print.line(e) } "); FxP_ParserContext *context = parse_string("collection.map -> (e) { Print.line(e) }\n"); char *inspection = fxp_parser_inspect(context); char *expected = "{\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"collection\"\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"map\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"function_definition\": {\n" " \"arguments\": {\n" " \"function_arguments\": [\n" " {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"e\"\n" " }\n" " }\n" " }\n" " ]\n" " },\n" " \"expressions\": [\n" " {\n" " \"method_call\": {\n" " \"receiver\": {\n" " \"lookup\": {\n" " \"type\": \"Class Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"Print\"\n" " }\n" " }\n" " },\n" " \"message\": {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"line\"\n" " }\n" " }\n" " },\n" " \"arguments\": [\n" " {\n" " \"lookup\": {\n" " \"type\": \"Identifier\",\n" " \"bit\": {\n" " \"STRING\": \"e\"\n" " }\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" " }\n" " }\n" " ]\n" "}"; assert_strings_equal(inspection, expected, "ast"); fxp_parser_context_free(context); free(inspection); return NULL; }
char *test_function_with_two_expressions() { // TODO: parser can't handle no terminating \n at end of expressions set /*spec_describe("function two expressions: -> {\n 1 + 1\n print 'word'}");*/ spec_describe("function two expressions: -> {\n 1 + 1\n print 'word'\n}\n"); FxP_ParserContext *context = parse_string("-> {\n 1 + 1\n print 'word'\n}\n"); setup_json(); element = json_object_get( json_object_get(expression, "function_definition"), "expressions"); assert_ints_equal(json_array_size(element), 2, "expressions size correct"); expression = json_object_get( json_object_get(expression, "function_definition"), "expressions"); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get( json_array_get( expression, 0), "method_call"), "receiver"), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "first expression receiver correct"); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get( json_array_get( expression, 0), "method_call"), "message"), "lookup"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "+", "first expression message correct"); element = json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get( json_array_get( expression, 0), "method_call"), "arguments"), 0), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "first expression arguments correct"); cleanup(); return NULL; }
char *test_function_with_expression() { spec_describe("function one expression: -> {\n1 + 1\n}"); FxP_ParserContext *context = parse_string("-> {\n1 + 1\n}\n"); setup_json(); element = json_object_get( json_object_get(expression, "function_definition"), "expressions"); assert_ints_equal(json_array_size(element), 1, "expressions size correct"); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get(expression, "function_definition"), "expressions"), 0), "method_call"), "receiver"), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "first expression receiver correct"); element = json_object_get( json_object_get( json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get(expression, "function_definition"), "expressions"), 0), "method_call"), "message"), "lookup"), "bit"), "STRING"); assert_strings_equal(json_string_value(element), "+", "first expression message correct"); element = json_object_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get( json_array_get( json_object_get( json_object_get(expression, "function_definition"), "expressions"), 0), "method_call"), "arguments"), 0), "literal"), "bit"), "INTEGER"); assert_ints_equal(json_integer_value(element), 1, "first expression arguments correct"); cleanup(); return NULL; }