Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 430bf0b8acb5
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 755f73a3c07c
Choose a head ref
  • 2 commits
  • 13 files changed
  • 1 contributor

Commits on Jun 4, 2017

  1. Copy the full SHA
    f3bf008 View commit details
  2. Copy the full SHA
    755f73a View commit details
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_comment_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

describe "Lexer comments" do
it "lexes without comments enabled" do
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_doc_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

describe "Lexer doc" do
it "lexes without doc enabled" do
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_macro_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

describe "Lexer macro" do
it "lexes simple macro" do
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

private def it_lexes(string, type)
it "lexes #{string.inspect}" do
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_string_array_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

private def it_should_be_valid_string_array_lexer(lexer)
token = lexer.next_token
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_string_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"
require "./lexer_objects/strings"

describe "Lexer string" do
2 changes: 1 addition & 1 deletion spec/compiler/lexer/location_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

private def assert_token_column_number(lexer, type, column_number)
token = lexer.next_token
2 changes: 1 addition & 1 deletion spec/compiler/parser/parser_doc_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

describe "Parser doc" do
[
5 changes: 4 additions & 1 deletion spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

private def regex(string, options = Regex::Options::None)
RegexLiteral.new(StringLiteral.new(string), options)
@@ -1271,6 +1271,9 @@ describe "Parser" do

it_parses "foo bar.baz(1) do\nend", Call.new(nil, "foo", args: [Call.new("bar".call, "baz", 1.int32)] of ASTNode, block: Block.new)

it_parses "1 rescue 2 if 3", If.new(3.int32, ExceptionHandler.new(1.int32, [Rescue.new(2.int32)]))
it_parses "1 ensure 2 if 3", If.new(3.int32, ExceptionHandler.new(1.int32, ensure: 2.int32))

assert_syntax_error "return do\nend", "unexpected token: do"

%w(def macro class struct module fun alias abstract include extend lib).each do |keyword|
2 changes: 1 addition & 1 deletion spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "../../spec_helper"
require "../../support/syntax"

private def expect_to_s(original, expected = original, emit_doc = false, file = __FILE__, line = __LINE__)
it "does to_s of #{original.inspect}", file, line do
148 changes: 1 addition & 147 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -4,122 +4,7 @@ ENV["CRYSTAL_PATH"] = "#{__DIR__}/../src"

require "spec"
require "../src/compiler/crystal/**"

include Crystal

struct Number
def int32
NumberLiteral.new to_s, :i32
end

def int64
NumberLiteral.new to_s, :i64
end

def float32
NumberLiteral.new to_f32.to_s, :f32
end

def float64
NumberLiteral.new to_f64.to_s, :f64
end
end

struct Bool
def bool
BoolLiteral.new self
end
end

class Array
def array
ArrayLiteral.new self
end

def array_of(type)
ArrayLiteral.new self, type
end

def path
Path.new self
end
end

class String
def var
Var.new self
end

def arg(default_value = nil, restriction = nil)
Arg.new self, default_value: default_value, restriction: restriction
end

def call
Call.new nil, self
end

def call(args : Array)
Call.new nil, self, args
end

def call(arg : ASTNode)
Call.new nil, self, [arg] of ASTNode
end

def call(arg1 : ASTNode, arg2 : ASTNode)
Call.new nil, self, [arg1, arg2] of ASTNode
end

def path(global = false)
Path.new self, global
end

def instance_var
InstanceVar.new self
end

def class_var
ClassVar.new self
end

def string
StringLiteral.new self
end

def float32
NumberLiteral.new self, :f32
end

def float64
NumberLiteral.new self, :f64
end

def symbol
SymbolLiteral.new self
end

def static_array_of(size : Int)
static_array_of NumberLiteral.new(size)
end

def static_array_of(size : ASTNode)
Generic.new(Path.global("StaticArray"), [path, size] of ASTNode)
end

def macro_literal
MacroLiteral.new(self)
end
end

class Crystal::ASTNode
def pointer_of
Generic.new(Path.global("Pointer"), [self] of ASTNode)
end

def splat
Splat.new(self)
end
end
require "./support/syntax"

class Crystal::Program
def union_of(type1, type2, type3)
@@ -215,31 +100,6 @@ def assert_after_cleanup(before, after)
result.node.to_s.strip.should eq(after.strip)
end

def assert_syntax_error(str, message = nil, line = nil, column = nil, metafile = __FILE__, metaline = __LINE__, metaendline = __END_LINE__)
it "says syntax error on #{str.inspect}", metafile, metaline, metaendline do
begin
parse str
fail "Expected SyntaxException to be raised", metafile, metaline
rescue ex : SyntaxException
if message
unless ex.message.not_nil!.includes?(message.not_nil!)
fail "Expected message to include #{message.inspect} but got #{ex.message.inspect}", metafile, metaline
end
end
if line
unless ex.line_number == line
fail "Expected line number to be #{line} but got #{ex.line_number}", metafile, metaline
end
end
if column
unless ex.column_number == column
fail "Expected column number to be #{column} but got #{ex.column_number}", metafile, metaline
end
end
end
end
end

def assert_error(str, message, inject_primitives = true)
str = inject_primitives(str) if inject_primitives
nodes = parse str
@@ -269,12 +129,6 @@ def assert_macro_internal(program, sub_node, macro_args, macro_body, expected)
result.should eq(expected)
end

def parse(string, wants_doc = false)
parser = Parser.new(string)
parser.wants_doc = wants_doc
parser.parse
end

def codegen(code, inject_primitives = true, debug = Crystal::Debug::None)
code = inject_primitives(code) if inject_primitives
node = parse code
149 changes: 149 additions & 0 deletions spec/support/syntax.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
require "spec"
require "../../src/compiler/crystal/syntax"

include Crystal

struct Number
def int32
NumberLiteral.new to_s, :i32
end

def int64
NumberLiteral.new to_s, :i64
end

def float32
NumberLiteral.new to_f32.to_s, :f32
end

def float64
NumberLiteral.new to_f64.to_s, :f64
end
end

struct Bool
def bool
BoolLiteral.new self
end
end

class Array
def array
ArrayLiteral.new self
end

def array_of(type)
ArrayLiteral.new self, type
end

def path
Path.new self
end
end

class String
def var
Var.new self
end

def arg(default_value = nil, restriction = nil)
Arg.new self, default_value: default_value, restriction: restriction
end

def call
Call.new nil, self
end

def call(args : Array)
Call.new nil, self, args
end

def call(arg : ASTNode)
Call.new nil, self, [arg] of ASTNode
end

def call(arg1 : ASTNode, arg2 : ASTNode)
Call.new nil, self, [arg1, arg2] of ASTNode
end

def path(global = false)
Path.new self, global
end

def instance_var
InstanceVar.new self
end

def class_var
ClassVar.new self
end

def string
StringLiteral.new self
end

def float32
NumberLiteral.new self, :f32
end

def float64
NumberLiteral.new self, :f64
end

def symbol
SymbolLiteral.new self
end

def static_array_of(size : Int)
static_array_of NumberLiteral.new(size)
end

def static_array_of(size : ASTNode)
Generic.new(Path.global("StaticArray"), [path, size] of ASTNode)
end

def macro_literal
MacroLiteral.new(self)
end
end

class Crystal::ASTNode
def pointer_of
Generic.new(Path.global("Pointer"), [self] of ASTNode)
end

def splat
Splat.new(self)
end
end

def assert_syntax_error(str, message = nil, line = nil, column = nil, metafile = __FILE__, metaline = __LINE__, metaendline = __END_LINE__)
it "says syntax error on #{str.inspect}", metafile, metaline, metaendline do
begin
parse str
fail "Expected SyntaxException to be raised", metafile, metaline
rescue ex : SyntaxException
if message
unless ex.message.not_nil!.includes?(message.not_nil!)
fail "Expected message to include #{message.inspect} but got #{ex.message.inspect}", metafile, metaline
end
end
if line
unless ex.line_number == line
fail "Expected line number to be #{line} but got #{ex.line_number}", metafile, metaline
end
end
if column
unless ex.column_number == column
fail "Expected column number to be #{column} but got #{ex.column_number}", metafile, metaline
end
end
end
end
end

def parse(string, wants_doc = false)
parser = Parser.new(string)
parser.wants_doc = wants_doc
parser.parse
end
Loading