소스 검색

Run prettier

master
Dylan Baker 5 년 전
부모
커밋
dfc72ec77b
5개의 변경된 파일21개의 추가작업 그리고 36개의 파일을 삭제
  1. 1
    2
      lib/chervil.rb
  2. 3
    3
      spec/env_spec.rb
  3. 1
    1
      spec/interpreter_spec.rb
  4. 1
    1
      spec/lexer_spec.rb
  5. 15
    29
      spec/parser_spec.rb

+ 1
- 2
lib/chervil.rb 파일 보기

8
 require 'chervil/token'
8
 require 'chervil/token'
9
 require 'chervil/version'
9
 require 'chervil/version'
10
 
10
 
11
-module Chervil
12
-end
11
+module Chervil; end

+ 3
- 3
spec/env_spec.rb 파일 보기

2
   RSpec.describe Env do
2
   RSpec.describe Env do
3
     it 'has arithmetic from core' do
3
     it 'has arithmetic from core' do
4
       env = Env.new
4
       env = Env.new
5
-      expect(env.get("+").call([1, 2], env)).to eq(3)
5
+      expect(env.get('+').call([1, 2], env)).to eq(3)
6
     end
6
     end
7
 
7
 
8
     it 'inherits from parent env' do
8
     it 'inherits from parent env' do
9
       parent = Env.new
9
       parent = Env.new
10
-      parent.set("x", 5)
10
+      parent.set('x', 5)
11
       child = Env.new(parent)
11
       child = Env.new(parent)
12
-      expect(child.get("x")).to eq(5)
12
+      expect(child.get('x')).to eq(5)
13
     end
13
     end
14
   end
14
   end
15
 end
15
 end

+ 1
- 1
spec/interpreter_spec.rb 파일 보기

9
     it 'interprets a definition and variable usage' do
9
     it 'interprets a definition and variable usage' do
10
       env = Env.new
10
       env = Env.new
11
       interpret('(define x 5)', env)
11
       interpret('(define x 5)', env)
12
-      expect(env.get("x")).to eq(AST::Number.new(5.0))
12
+      expect(env.get('x')).to eq(AST::Number.new(5.0))
13
       expect(interpret('x', env).first).to eq(5.0)
13
       expect(interpret('x', env).first).to eq(5.0)
14
     end
14
     end
15
 
15
 

+ 1
- 1
spec/lexer_spec.rb 파일 보기

45
     end
45
     end
46
 
46
 
47
     it 'lexes booleans' do
47
     it 'lexes booleans' do
48
-      lexer = Lexer.new("#t #f")
48
+      lexer = Lexer.new('#t #f')
49
       expect(lexer.get_next_token).to eq(Token.new(:boolean, true))
49
       expect(lexer.get_next_token).to eq(Token.new(:boolean, true))
50
       expect(lexer.get_next_token).to eq(Token.new(:boolean, false))
50
       expect(lexer.get_next_token).to eq(Token.new(:boolean, false))
51
     end
51
     end

+ 15
- 29
spec/parser_spec.rb 파일 보기

20
 
20
 
21
     it 'parses booleans' do
21
     it 'parses booleans' do
22
       expect(parse('#t #f')).to eq(
22
       expect(parse('#t #f')).to eq(
23
-        [
24
-          AST::Boolean.new(true),
25
-          AST::Boolean.new(false),
26
-        ]
23
+        [AST::Boolean.new(true), AST::Boolean.new(false)]
27
       )
24
       )
28
     end
25
     end
29
 
26
 
45
     it 'parses a nested expression' do
42
     it 'parses a nested expression' do
46
       expect(parse('(+ (+ 1 2) (- 3 4))').first).to eq(
43
       expect(parse('(+ (+ 1 2) (- 3 4))').first).to eq(
47
         AST::Application.new(
44
         AST::Application.new(
48
-          AST::Identifier.new("+"),
45
+          AST::Identifier.new('+'),
49
           [
46
           [
50
             AST::Application.new(
47
             AST::Application.new(
51
-              AST::Identifier.new("+"),
52
-              [
53
-                AST::Number.new(1.0),
54
-                AST::Number.new(2.0),
55
-              ]
48
+              AST::Identifier.new('+'),
49
+              [AST::Number.new(1.0), AST::Number.new(2.0)]
56
             ),
50
             ),
57
             AST::Application.new(
51
             AST::Application.new(
58
-              AST::Identifier.new("-"),
59
-              [
60
-                AST::Number.new(3.0),
61
-                AST::Number.new(4.0),
62
-              ]
63
-            ),
52
+              AST::Identifier.new('-'),
53
+              [AST::Number.new(3.0), AST::Number.new(4.0)]
54
+            )
64
           ]
55
           ]
65
         )
56
         )
66
       )
57
       )
69
     it 'parses a function definition' do
60
     it 'parses a function definition' do
70
       expect(parse('(define (square x) (* x x))').first).to eq(
61
       expect(parse('(define (square x) (* x x))').first).to eq(
71
         AST::Definition.new(
62
         AST::Definition.new(
72
-          AST::Identifier.new("square"),
63
+          AST::Identifier.new('square'),
73
           AST::Function.new(
64
           AST::Function.new(
74
-            AST::Identifier.new("square"),
75
-            [
76
-              AST::Identifier.new("x")
77
-            ],
65
+            AST::Identifier.new('square'),
66
+            [AST::Identifier.new('x')],
78
             [
67
             [
79
               AST::Application.new(
68
               AST::Application.new(
80
-                AST::Identifier.new("*"),
81
-                [
82
-                  AST::Identifier.new("x"),
83
-                  AST::Identifier.new("x"),
84
-                ]
69
+                AST::Identifier.new('*'),
70
+                [AST::Identifier.new('x'), AST::Identifier.new('x')]
85
               )
71
               )
86
             ]
72
             ]
87
           )
73
           )
90
     end
76
     end
91
 
77
 
92
     it 'returns a syntax error object instead of raising' do
78
     it 'returns a syntax error object instead of raising' do
93
-      expect(parse('(+ 1')).to eq(Error.new("Expected rparen but got eof"))
94
-      expect(parse('1)')).to eq(Error.new("Unexpected token rparen: )"))
79
+      expect(parse('(+ 1')).to eq(Error.new('Expected rparen but got eof'))
80
+      expect(parse('1)')).to eq(Error.new('Unexpected token rparen: )'))
95
     end
81
     end
96
 
82
 
97
     it 'parses a conditional' do
83
     it 'parses a conditional' do
99
         AST::Conditional.new(
85
         AST::Conditional.new(
100
           AST::Boolean.new(true),
86
           AST::Boolean.new(true),
101
           AST::Number.new(1.0),
87
           AST::Number.new(1.0),
102
-          AST::Number.new(0.0),
88
+          AST::Number.new(0.0)
103
         )
89
         )
104
       )
90
       )
105
     end
91
     end

Loading…
취소
저장