diff --git a/sloxTests/InterpreterTests.swift b/sloxTests/InterpreterTests.swift index 33a7d75..77da487 100644 --- a/sloxTests/InterpreterTests.swift +++ b/sloxTests/InterpreterTests.swift @@ -50,7 +50,7 @@ final class InterpreterTests: XCTestCase { } } - func testInterpretNumericBinaryExpression() throws { + func testInterpretBinaryExpressionInvolvingIntegers() throws { let input = "21 * 2" let interpreter = Interpreter() let actual = try interpreter.interpretRepl(source: input)! @@ -58,6 +58,22 @@ final class InterpreterTests: XCTestCase { XCTAssertEqual(actual, expected) } + func testInterpretBinaryExpressionInvolvingDoubles() throws { + let input = "21.0 * 2.0" + let interpreter = Interpreter() + let actual = try interpreter.interpretRepl(source: input)! + let expected: LoxValue = .double(42.0) + XCTAssertEqual(actual, expected) + } + + func testInterpretBinaryExpressionInvolvingAnIntAndADouble() throws { + let input = "21.0 * 2" + let interpreter = Interpreter() + let actual = try interpreter.interpretRepl(source: input)! + let expected: LoxValue = .double(42.0) + XCTAssertEqual(actual, expected) + } + func testInterpretStringlyBinaryExpression() throws { let input = "\"forty\" + \"-two\"" let interpreter = Interpreter() @@ -416,6 +432,19 @@ foo[2] XCTAssertEqual(actual, expected) } + func testInterpretAccessingElementOfListWithDouble() throws { + let input = """ +var foo = [1, 2, 3, 4, 5]; +foo[2.0] +""" + + let interpreter = Interpreter() + let expectedError = RuntimeError.indexMustBeAnInteger + XCTAssertThrowsError(try interpreter.interpretRepl(source: input)!) { actualError in + XCTAssertEqual(actualError as! RuntimeError, expectedError) + } + } + func testInterpretMutationOfList() throws { let input = """ var foo = [1, 2, 3, 4, 5];