Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b9850ade85
Fetching contributors…

Cannot retrieve contributors at this time

file 129 lines (105 sloc) 2.172 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
require 'test_helper'

module Noscript
  class IntegrationTest < MiniTest::Unit::TestCase

    def compile(code)
      Noscript.eval_noscript(code)
    end

    def test_hello_world
      output = `./bin/noscript examples/hello_world.ns`.split("\n")

      assert_equal [
        "Negative johnny is",
        "-4000",
        "43",
        "760",
        "111",
        "cool!",
        "bar",
        "baz",
        "Johnny is still",
        "4000",
        "lord",
        "hello world",
      ], output
    end

    def test_objects
      output = `./bin/noscript examples/objects.ns`.split("\n")

      assert_equal [
        "running!",
        "10",
        "vroom",
        "99",
      ], output
    end

    def test_dci
      output = `./bin/noscript examples/dci.ns`.split("\n")

      assert_equal [
        "John has now 1 elements in his cart"
      ], output
    end

    def test_traits
      output = `./bin/noscript examples/traits.ns`.split("\n")

      assert_equal [
        "John is running a profitable business named Johnny Cash Inc.!",
        "John is running at 10 km/h",
        "Sir John is running a profitable business named Johnny Cash Inc.!"
      ], output
    end

    def test_conditionals
      [
        """
foo = 3

if foo != 91
'ok'
end
""",

        """
foo = 3

if foo > 2
'ok'
else
'ko'
end
""",

        """
foo = 3

if foo < 2
'ko'
else
'ok'
end
""",

        """
foo = 3

if foo <= 3
'ok'
else
'ko'
end
""",

        """
foo = 4

if foo >= 3
'ok'
else
'ko'
end
"""
      ].each do |code|
        assert_equal 'ok', compile(code)
      end
    end

    def test_while
      [
        """
foo = 3

while foo > 0
foo = foo - 1
end

foo
"""
      ].each do |code|
        assert_equal 0, compile(code)
      end
    end

  end
end
Something went wrong with that request. Please try again.