ScriptLoading.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // Copyright (c) 2009 Brandon Jones
  3. //
  4. // This software is provided 'as-is', without any express or implied
  5. // warranty. In no event will the authors be held liable for any damages
  6. // arising from the use of this software.
  7. //
  8. // Permission is granted to anyone to use this software for any purpose,
  9. // including commercial applications, and to alter it and redistribute it
  10. // freely, subject to the following restrictions:
  11. //
  12. // 1. The origin of this software must not be misrepresented; you must not
  13. // claim that you wrote the original software. If you use this software
  14. // in a product, an acknowledgment in the product documentation would be
  15. // appreciated but is not required.
  16. //
  17. // 2. Altered source versions must be plainly marked as such, and must not be
  18. // misrepresented as being the original software.
  19. //
  20. // 3. This notice may not be removed or altered from any source
  21. // distribution.
  22. //
  23. #include <gtest/gtest.h>
  24. #include <sqrat.h>
  25. #include "Fixture.h"
  26. using namespace Sqrat;
  27. TEST_F(SqratTest, LoadScriptFromString) {
  28. //
  29. // Compile and run from string
  30. //
  31. DefaultVM::Set(vm);
  32. Script script;
  33. script.CompileString(_SC(" \
  34. x <- 1 + 2; \
  35. gTest.EXPECT_STR_EQ(x, 3); \
  36. "));
  37. if (Sqrat::Error::Occurred(vm)) {
  38. FAIL() << _SC("Script Compile Failed: ") << Sqrat::Error::Message(vm);
  39. }
  40. script.Run();
  41. if (Sqrat::Error::Occurred(vm)) {
  42. FAIL() << _SC("Script Run Failed: ") << Sqrat::Error::Message(vm);
  43. }
  44. }
  45. TEST_F(SqratTest, LoadScriptFromFile) {
  46. //
  47. // Compile and run from file
  48. //
  49. DefaultVM::Set(vm);
  50. Script script;
  51. script.CompileFile(_SC("scripts/hello.nut"));
  52. if (Sqrat::Error::Occurred(vm)) {
  53. FAIL() << _SC("Script Compile Failed: ") << Sqrat::Error::Message(vm);
  54. }
  55. script.Run();
  56. if (Sqrat::Error::Occurred(vm)) {
  57. FAIL() << _SC("Script Run Failed: ") << Sqrat::Error::Message(vm);
  58. }
  59. }