]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Started adding specs for type definitions and annotations
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 28 Oct 2014 20:30:47 +0000 (16:30 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 28 Oct 2014 20:30:47 +0000 (16:30 -0400)
spec/parser_spec.rb

index d7f024765f92c16858aec311f262b78c20dd39d7..23f96229c0345fe02c42d8a550404c15b5a9158b 100644 (file)
@@ -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