Add some more automated test snippets

This commit is contained in:
Sam Vervaeck 2023-06-12 16:54:41 +02:00
parent a3f40d51ef
commit 8addcb0990
Signed by: samvv
SSH key fingerprint: SHA256:dIg0ywU1OP+ZYifrYxy8c5esO72cIKB+4/9wkZj1VaY
11 changed files with 163 additions and 0 deletions

View file

@ -0,0 +1,8 @@
@expect_diagnostic 2010
if 1.
True
@expect_diagnostic 2010
if "a".
False

View file

@ -0,0 +1,36 @@
# Advanced test for instance arguments as type classses
# From the paper 'On the Bright Side of Type Classes'
# Representation of the type class
struct Eq a.
equal: a -> a -> Bool
let primBoolEq a b = match (a, b).
(True, True) => True
(False, False) => True
_ => False
# Class Eq default method
let equal {{ eqT : Eq a }} : {{ Eq a }} -> a -> a -> Bool = eqT.equal
# Instance Eq Bool
let eqBool : Eq Bool = Eq {
equal = primBoolEq
}
# Instance Eq (List a)
let primListEq a b = match (a, b).
([], []) => True
(_, []) => False
([], _) => False
(a :: b, c :: d) => equal a c && primListEq b c
# Instance Eq a => Eq List a
let listEq : Eq a -> Eq (List a) = Eq {
equal = primListEq
}
equal True False
equal 1 2
equal 1 False

View file

@ -0,0 +1,17 @@
# Mutually recusive functions
let is_odd x.
if x == 1.
return True
else.
return is_even (x-1)
let is_even x.
if x == 0.
return True
else.
return is_odd (x-1)
@:Bool is_even 1

View file

@ -0,0 +1,12 @@
# Testing whether nested variable declarations work
let id x.
let foo = x
return foo
@:Int id 1
@:Bool id True
@:Int id 1
@:String id "foo"

View file

@ -0,0 +1,13 @@
enum MyList a.
Nil
Pair a (MyList a)
let (Pair True Nil) : MyList Bool
let (Pair "foo" Nil) : MyList String
@expect_diagnostic 2010
let (Pair 1 Nil) : MyList Bool
let Nil : MyList a

View file

@ -0,0 +1,10 @@
# Simple test for instance arguments
implicit let theanswer = 1
let is_answer {{ a : Int }} x = a == x
is_answer 1
is_answer 2
is_answer 42

View file

@ -0,0 +1,16 @@
let pair x y = (x, y)
let p1 = pair 1 1
let p2 = (1, True)
let p3 = (False, 1)
@:Int p1.0
@:Int p1.1
@:Int p2.0
@:Bool p2.1
@:Bool p3.0
@:Int p3.1

View file

@ -0,0 +1,10 @@
enum List a.
Nil
Pair a (List a)
let x : List Int
@expect_diagnostic 2010
let y : List Bool = x
let z : List String

View file

@ -0,0 +1,24 @@
class Eq a.
let eq : a -> a -> Bool
class Show a.
let show : a -> String
instance Eq String.
let eq a b = True
instance Show Bool.
let show s = "a boolean"
instance Show Int.
let show s = "a string"
let repr_eq_1 x y : (Show a, Show b) => a -> b -> Bool = eq (show x) (show y)
@expect_diagnostic 2201
let repr_eq_2 x y : (Show b) => a -> b -> Bool = eq (show x) (show y)
@expect_diagnostic 2201
let repr_eq_3 x y : a -> b -> Bool = eq (show x) (show y)

View file

@ -0,0 +1,6 @@
# Testing variable typing
@expect_diagnostic 2010
let a: Int = "foo"

View file

@ -0,0 +1,11 @@
let wrong x.
if True.
return 1
elif False.
return 2
else.
@expect_diagnostic 2010
return "foo"
wrong 1