+class QuoteToCTests(unittest.TestCase):
+ def test_quotes_integer_literals(self):
+ for i in range(5):
+ expected = stutter.CFunctionCallExpression(
+ 'makeObjectPointerFromInteger',
+ [stutter.CIntegerLiteralExpression(i)],
+ )
+
+ actual = stutter.quote_to_c(i)
+
+ self.assertEqual(expected, actual)
+
+ def test_quotes_string_literals(self):
+ s = 'Hello, world'
+ expected = stutter.CFunctionCallExpression(
+ 'makeObjectPointerFromString',
+ [stutter.CStringLiteralExpression(s)],
+ )
+
+ actual = stutter.quote_to_c(s)
+
+ self.assertEqual(expected, actual)
+
+class EvaluateApplicationArgumentsToCTests(unittest.TestCase):
+ def test_evaluates_empty_to_null(self):
+ expected = stutter.CVariableExpression('NULL')
+ actual = stutter.evaluate_application_arguments_to_c(())
+
+ self.assertEqual(expected, actual)
+
+ def test_evaluates_one_argument_to_cons(self):
+ argument = 42
+
+ sentinel = stutter.CStringLiteralExpression('1bd9707e76f8f807f3bad3e39049fea4a36d8ef2f8e2ed471ec755f7adb291d5')
+
+ def mock(argument_to_quote):
+ if argument_to_quote == argument:
+ return sentinel
+
+ expected = stutter.CFunctionCallExpression(
+ 'c_cons',
+ (sentinel, stutter.CVariableExpression('NULL')),
+ )
+
+ actual = stutter.evaluate_application_arguments_to_c(
+ (argument,),
+ quote_to_c = mock,
+ )
+
+ self.assertEqual(expected, actual)
+
+class EvaluateApplicationToCTests(unittest.TestCase):
+ def test_evaluates_function_calls_with_no_arguments(self):
+ name = 'name'
+
+ sentinel = stutter.CVariableExpression('NULL')
+
+ def mock(arguments):
+ assert arguments == ()
+ return sentinel
+
+ result = stutter.evaluate_application_to_c(
+ (stutter.Symbol(name),),
+ evaluate_application_arguments_to_c = mock,
+ )
+
+ self.assertEqual(result.name, name)
+ self.assertEqual(len(result.arguments), 1)
+ self.assertIs(result.arguments[0], sentinel)
+
+ def test_evaluates_function_calls_with_arguments(self):
+ name = 'print'
+ argument = 42
+
+ sentinel = stutter.CFunctionCallExpression(
+ 'cons',
+ [
+ stutter.CFunctionCallExpression(
+ 'makeObjectPointerFromInteger',
+ [stutter.CIntegerLiteralExpression(argument)],
+ ),
+ ],
+ )
+
+ def mock(arguments):
+ assert arguments == (argument,)
+ return sentinel
+
+ result = stutter.evaluate_application_to_c(
+ (stutter.Symbol(name), argument),
+ evaluate_application_arguments_to_c = mock,
+ )
+
+ self.assertEqual(result.name, name)
+ self.assertEqual(len(result.arguments), 1)
+ self.assertIs(result.arguments[0], sentinel)
+