From acb4362f28e783632a5c79db98f14b60aa12f175 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Sun, 1 Nov 2020 21:37:45 +0200 Subject: Move project to C++17 --- JSImpl/test/Test.vcxproj | 114 +---------------------------------------------- 1 file changed, 2 insertions(+), 112 deletions(-) (limited to 'JSImpl/test/Test.vcxproj') diff --git a/JSImpl/test/Test.vcxproj b/JSImpl/test/Test.vcxproj index 3abf38f..b2e4e83 100644 --- a/JSImpl/test/Test.vcxproj +++ b/JSImpl/test/Test.vcxproj @@ -5,18 +5,10 @@ Debug Win32 - - Debug - x64 - Release Win32 - - Release - x64 - {45DC8C7C-3113-8E0D-DAFF-7310C6150A0F} @@ -33,13 +25,6 @@ v142 true - - 16.0 - Application - true - v142 - true - 16.0 Application @@ -47,28 +32,15 @@ v142 true - - 16.0 - Application - false - v142 - true - - - - - - - ..\build\bin\Debug\ @@ -77,13 +49,6 @@ .exe true - - ..\build\bin\Debug\ - ..\build\obj\Debug\x64\Debug\Test\ - Test - .exe - true - ..\build\bin\Release\ ..\build\obj\Release\Release\Test\ @@ -91,13 +56,6 @@ .exe false - - ..\build\bin\Release\ - ..\build\obj\Release\x64\Release\Test\ - Test - .exe - false - %(AdditionalOptions) @@ -112,39 +70,7 @@ Level4 true - stdcpp14 - EditAndContinue - $(IntDir)Test.compile.pdb - Caret - - - _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories) - - - Console - true - $(OutDir)Test.pdb - ;%(AdditionalLibraryDirectories) - $(OutDir)Test.exe - mainCRTStartup - - - - - %(AdditionalOptions) - Disabled - googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories) - _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - false - true - EnableFastChecks - MultiThreadedDebugDLL - true - - Level4 - true - stdcpp14 + stdcpp17 EditAndContinue $(IntDir)Test.compile.pdb Caret @@ -160,7 +86,6 @@ ;%(AdditionalLibraryDirectories) $(OutDir)Test.exe mainCRTStartup - MachineX64 @@ -177,41 +102,7 @@ Level4 true - stdcpp14 - ProgramDatabase - $(IntDir)Test.compile.pdb - Caret - - - _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories) - - - Console - true - $(OutDir)Test.pdb - true - true - ;%(AdditionalLibraryDirectories) - $(OutDir)Test.exe - mainCRTStartup - - - - - %(AdditionalOptions) - MaxSpeed - googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;..\..\spasm\src\asm;%(AdditionalIncludeDirectories) - _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - false - true - true - MultiThreadedDLL - true - - Level4 - true - stdcpp14 + stdcpp17 ProgramDatabase $(IntDir)Test.compile.pdb Caret @@ -229,7 +120,6 @@ ;%(AdditionalLibraryDirectories) $(OutDir)Test.exe mainCRTStartup - MachineX64 -- cgit v1.3.1-26-gb76a From 5521d5857b122699120fbd749776dea44ffaa35b Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Mon, 2 Nov 2020 09:06:17 +0200 Subject: Add tests for the AST Interpreter --- JSImpl/test/ASTInterpreterTests.cpp | 58 +++++++++++++++++++++++++++++++++++++ JSImpl/test/Test.make | 6 ++++ JSImpl/test/Test.vcxproj | 2 ++ JSImpl/test/Test.vcxproj.filters | 1 + 4 files changed, 67 insertions(+) create mode 100644 JSImpl/test/ASTInterpreterTests.cpp (limited to 'JSImpl/test/Test.vcxproj') diff --git a/JSImpl/test/ASTInterpreterTests.cpp b/JSImpl/test/ASTInterpreterTests.cpp new file mode 100644 index 0000000..389f53c --- /dev/null +++ b/JSImpl/test/ASTInterpreterTests.cpp @@ -0,0 +1,58 @@ +#include + +#include +#include +#include +#include +#include + +struct ASTInterpret : ::testing::Test +{ + void Run(const char* program) + { + auto tokens = Tokenize(program).tokens; + auto expr = Parse(tokens); + Interpreter.Run(expr.get()); + } + + bool HasVariable(const char* name) + { + return Interpreter.HasVariable(name); + } + + double ValueAsNumber(const char* name) + { + return std::get(*Interpreter.ModifyVariable(name)); + } + + IPLString ValueAsString(const char* name) + { + return std::get(*Interpreter.ModifyVariable(name)); + } + + ASTInterpreter Interpreter; +}; + +TEST_F(ASTInterpret, VarNumber) +{ + Run("var answer = 6 * 7"); + ASSERT_TRUE(HasVariable("answer")); + ASSERT_DOUBLE_EQ(ValueAsNumber("answer"), 42.0); +} + +TEST_F(ASTInterpret, VarString) +{ + Run("var name = 'John' + ' ' + 'Doe'"); + ASSERT_TRUE(HasVariable("name")); + ASSERT_EQ(ValueAsString("name"), "John Doe"); +} + +TEST_F(ASTInterpret, StringPlusNumberNotSupported) +{ + ASSERT_THROW(Run("var data = 'John Doe' + 42"), std::runtime_error); +} + +TEST_F(ASTInterpret, StringMinusString) +{ + ASSERT_THROW(Run("var data = 'John' - 'Doe'"), std::runtime_error); +} diff --git a/JSImpl/test/Test.make b/JSImpl/test/Test.make index 38d963e..0510fa2 100644 --- a/JSImpl/test/Test.make +++ b/JSImpl/test/Test.make @@ -65,6 +65,7 @@ ifeq ($(config),debug) LINKCMD = $(CXX) -o $(TARGET) $(LINKOBJS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS) OBJRESP = OBJECTS := \ + $(OBJDIR)/ASTInterpreterTests.o \ $(OBJDIR)/CodeGenerationTests.o \ $(OBJDIR)/LexerTests.o \ $(OBJDIR)/ParserTests.o \ @@ -102,6 +103,7 @@ ifeq ($(config),release) LINKCMD = $(CXX) -o $(TARGET) $(LINKOBJS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS) OBJRESP = OBJECTS := \ + $(OBJDIR)/ASTInterpreterTests.o \ $(OBJDIR)/CodeGenerationTests.o \ $(OBJDIR)/LexerTests.o \ $(OBJDIR)/ParserTests.o \ @@ -178,6 +180,10 @@ $(LDRESP): $(LDDEPS) | $(TARGETDIR) $(OBJDIRS) $(SILENT) echo $^ > $@ endif +$(OBJDIR)/ASTInterpreterTests.o: ASTInterpreterTests.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/. + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + $(OBJDIR)/CodeGenerationTests.o: CodeGenerationTests.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/. @echo $(notdir $<) $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" diff --git a/JSImpl/test/Test.vcxproj b/JSImpl/test/Test.vcxproj index b2e4e83..c33f333 100644 --- a/JSImpl/test/Test.vcxproj +++ b/JSImpl/test/Test.vcxproj @@ -123,6 +123,8 @@ + + diff --git a/JSImpl/test/Test.vcxproj.filters b/JSImpl/test/Test.vcxproj.filters index 412f2b7..50fcfb0 100644 --- a/JSImpl/test/Test.vcxproj.filters +++ b/JSImpl/test/Test.vcxproj.filters @@ -1,6 +1,7 @@ + -- cgit v1.3.1-26-gb76a