From 21a34eef896c7c89d1d3b3d03bdb77992225524a Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 28 Oct 2014 16:30:47 -0400 Subject: [PATCH] Started adding specs for type definitions and annotations --- spec/parser_spec.rb | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index d7f0247..23f9622 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -28,6 +28,71 @@ describe "sclpl grammar" do end context "type definitions" do + it "should parse a simple type definition" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is int;')).to eq([ ['T_ID:type', 'T_ID:foo', 'T_ID:int'] ]) + end + + it "should parse a function type definition with no args" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is (-> int ());')).to eq([ + ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:->', 'T_ID:int', []]] ]) + end + + it "should parse a function type definition with one arg" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is (-> int (int));')).to eq([ + ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:->', 'T_ID:int', ['T_ID:int']]] ]) + end + + it "should parse a function type definition with two args" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is (-> int (int, int));')).to eq([ + ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:->', 'T_ID:int', ['T_ID:int', 'T_ID:int']]] ]) + end + + it "should parse a function type definition with three args" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is (-> int (int, int, int));')).to eq([ + ['T_ID:type', 'T_ID:foo', 'T_ID:is', ['T_ID:->', 'T_ID:int', ['T_ID:int', 'T_ID:int', 'T_ID:int']]] ]) + end + + it "should parse a tuple type definition with one field" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is {int};')).to eq([ + ['T_ID:type', 'T_ID:foo', ['T_ID:tuple', 'T_ID:int']] ]) + end + + it "should parse a tuple type definition with two fields" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is {int,int};')).to eq([ + ['T_ID:type', 'T_ID:foo', ['T_ID:tuple', 'T_ID:int', 'T_ID:int']] ]) + end + + it "should parse a tuple type definition with three fields" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is {int,int,int};')).to eq([ + ['T_ID:type', 'T_ID:foo', ['T_ID:tuple', 'T_ID:int', 'T_ID:int', 'T_ID:int']] ]) + end + + it "should parse a record type definition with one field" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is { int a };')).to eq([ + ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a']]] ]) + end + + it "should parse a record type definition with two fields" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is { int a, int b };')).to eq([ + ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a'], ['T_ID:int', 'T_ID:b']]] ]) + end + + it "should parse a record type definition with three fields" do + pending "Type annotations have not been implemented yet" + expect(ast('type foo is { int a, int b };')).to eq([ + ['T_ID:type', 'T_ID:foo', ['T_ID:record', ['T_ID:int', 'T_ID:a'], ['T_ID:int', 'T_ID:b'], ['T_ID:int', 'T_ID:c']]] ]) + end + end context "definitions" do -- 2.52.0