loxxy 0.0.11 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_helper' # Use the RSpec framework
4
+ require 'stringio'
5
+
6
+ # Load the class under test
7
+ require_relative '../lib/loxxy/interpreter'
8
+
9
+ module Loxxy
10
+ # This spec contains the bare bones test for the Interpreter class.
11
+ # The execution of Lox code is tested elsewhere.
12
+ describe Interpreter do
13
+ let(:sample_cfg) do
14
+ { ostream: StringIO.new }
15
+ end
16
+ subject { Interpreter.new(sample_cfg) }
17
+
18
+ context 'Initialization:' do
19
+ it 'should accept a option Hash at initialization' do
20
+ expect { Interpreter.new(sample_cfg) }.not_to raise_error
21
+ end
22
+
23
+ it 'should know its config options' do
24
+ expect(subject.config).to eq(sample_cfg)
25
+ end
26
+ end # context
27
+
28
+ context 'Evaluating arithmetic operations code:' do
29
+ it 'should evaluate an addition of two numbers' do
30
+ result = subject.evaluate('123 + 456; // => 579')
31
+ expect(result).to be_kind_of(Loxxy::Datatype::Number)
32
+ expect(result == 579).to be_true
33
+ end
34
+
35
+ it 'should evaluate a subtraction of two numbers' do
36
+ result = subject.evaluate('4 - 3; // => 1')
37
+ expect(result).to be_kind_of(Loxxy::Datatype::Number)
38
+ expect(result == 1).to be_true
39
+ end
40
+
41
+ it 'should evaluate a multiplication of two numbers' do
42
+ result = subject.evaluate('5 * 3; // => 15')
43
+ expect(result).to be_kind_of(Loxxy::Datatype::Number)
44
+ expect(result == 15).to be_true
45
+ end
46
+
47
+ it 'should evaluate a division of two numbers' do
48
+ result = subject.evaluate('8 / 2; // => 4')
49
+ expect(result).to be_kind_of(Loxxy::Datatype::Number)
50
+ expect(result == 4).to be_true
51
+ end
52
+ end # context
53
+
54
+ context 'Evaluating Lox code:' do
55
+ let(:hello_world) { 'print "Hello, world!";' }
56
+
57
+ it 'should evaluate core data types' do
58
+ result = subject.evaluate('true; // Not false')
59
+ expect(result).to be_kind_of(Loxxy::Datatype::True)
60
+ end
61
+
62
+ it 'should evaluate string concatenation' do
63
+ result = subject.evaluate('"str" + "ing"; // => "string"')
64
+ expect(result).to be_kind_of(Loxxy::Datatype::LXString)
65
+ expect(result == 'string').to be_true
66
+ end
67
+
68
+ it 'should perform the equality tests of two values' do
69
+ [
70
+ ['nil == nil;', true],
71
+ ['true == true;', true],
72
+ ['true == false;', false],
73
+ ['1 == 1;', true],
74
+ ['1 == 2;', false],
75
+ ['0 == 0;', true],
76
+ ['"str" == "str";', true],
77
+ ['"str" == "ing";', false],
78
+ ['"" == "";', true],
79
+ ['nil == false;', false],
80
+ ['false == 0;', false],
81
+ ['0 == "0";', false]
82
+ ].each do |(source, predicted)|
83
+ lox = Loxxy::Interpreter.new
84
+ result = lox.evaluate(source)
85
+ expect(result.value == predicted).to be_truthy
86
+ end
87
+ end
88
+
89
+ it 'should perform the inequality test of two values' do
90
+ [
91
+ ['nil != nil;', false],
92
+ ['true != true;', false],
93
+ ['true != false;', true],
94
+ ['1 != 1;', false],
95
+ ['1 != 2;', true],
96
+ ['0 != 0;', false],
97
+ ['"str" != "str";', false],
98
+ ['"str" != "ing";', true],
99
+ ['"" != "";', false],
100
+ ['nil != false;', true],
101
+ ['false != 0;', true],
102
+ ['0 != "0";', true]
103
+ ].each do |(source, predicted)|
104
+ lox = Loxxy::Interpreter.new
105
+ result = lox.evaluate(source)
106
+ expect(result.value == predicted).to be_truthy
107
+ end
108
+ end
109
+
110
+ it 'should print the hello world message' do
111
+ expect { subject.evaluate(hello_world) }.not_to raise_error
112
+ expect(sample_cfg[:ostream].string).to eq('Hello, world!')
113
+ end
114
+ end # context
115
+ end # describe
116
+ end # module
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loxxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2021-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley
@@ -84,12 +84,16 @@ files:
84
84
  - README.md
85
85
  - Rakefile
86
86
  - lib/loxxy.rb
87
+ - lib/loxxy/ast/all_lox_nodes.rb
87
88
  - lib/loxxy/ast/ast_builder.rb
88
89
  - lib/loxxy/ast/ast_visitor.rb
89
90
  - lib/loxxy/ast/lox_binary_expr.rb
90
91
  - lib/loxxy/ast/lox_compound_expr.rb
91
92
  - lib/loxxy/ast/lox_literal_expr.rb
92
93
  - lib/loxxy/ast/lox_node.rb
94
+ - lib/loxxy/ast/lox_noop_expr.rb
95
+ - lib/loxxy/ast/lox_print_stmt.rb
96
+ - lib/loxxy/back_end/engine.rb
93
97
  - lib/loxxy/datatype/all_datatypes.rb
94
98
  - lib/loxxy/datatype/boolean.rb
95
99
  - lib/loxxy/datatype/builtin_datatype.rb
@@ -103,12 +107,18 @@ files:
103
107
  - lib/loxxy/front_end/parser.rb
104
108
  - lib/loxxy/front_end/raw_parser.rb
105
109
  - lib/loxxy/front_end/scanner.rb
110
+ - lib/loxxy/interpreter.rb
106
111
  - lib/loxxy/version.rb
107
112
  - loxxy.gemspec
113
+ - spec/back_end/engine_spec.rb
114
+ - spec/datatype/boolean_spec.rb
108
115
  - spec/datatype/lx_string_spec.rb
116
+ - spec/datatype/nil_spec.rb
117
+ - spec/datatype/number_spec.rb
109
118
  - spec/front_end/parser_spec.rb
110
119
  - spec/front_end/raw_parser_spec.rb
111
120
  - spec/front_end/scanner_spec.rb
121
+ - spec/interpreter_spec.rb
112
122
  - spec/loxxy_spec.rb
113
123
  - spec/spec_helper.rb
114
124
  homepage: https://github.com/famished-tiger/loxxy
@@ -136,8 +146,13 @@ signing_key:
136
146
  specification_version: 4
137
147
  summary: An implementation of the Lox programming language. WIP
138
148
  test_files:
149
+ - spec/back_end/engine_spec.rb
150
+ - spec/datatype/boolean_spec.rb
139
151
  - spec/datatype/lx_string_spec.rb
152
+ - spec/datatype/nil_spec.rb
153
+ - spec/datatype/number_spec.rb
140
154
  - spec/front_end/parser_spec.rb
141
155
  - spec/front_end/raw_parser_spec.rb
142
156
  - spec/front_end/scanner_spec.rb
157
+ - spec/interpreter_spec.rb
143
158
  - spec/loxxy_spec.rb