Add some more automated test snippets
This commit is contained in:
parent
a3f40d51ef
commit
8addcb0990
11 changed files with 163 additions and 0 deletions
8
test/checker/if_part_test_is_bool.bolt
Normal file
8
test/checker/if_part_test_is_bool.bolt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
@expect_diagnostic 2010
|
||||||
|
if 1.
|
||||||
|
True
|
||||||
|
|
||||||
|
@expect_diagnostic 2010
|
||||||
|
if "a".
|
||||||
|
False
|
36
test/checker/instance_arguments_type_classes.bolt.disabled
Normal file
36
test/checker/instance_arguments_type_classes.bolt.disabled
Normal 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
|
17
test/checker/mutual_recursion_is_odd_is_even.bolt
Normal file
17
test/checker/mutual_recursion_is_odd_is_even.bolt
Normal 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
|
||||||
|
|
12
test/checker/nested_vars_reaching_parent_scope.bolt
Normal file
12
test/checker/nested_vars_reaching_parent_scope.bolt
Normal 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"
|
||||||
|
|
13
test/checker/pattern_matching_variant.bolt
Normal file
13
test/checker/pattern_matching_variant.bolt
Normal 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
|
||||||
|
|
10
test/checker/simple_instance_arguments.bolt.disabled
Normal file
10
test/checker/simple_instance_arguments.bolt.disabled
Normal 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
|
16
test/checker/simple_tuple_test.bolt
Normal file
16
test/checker/simple_tuple_test.bolt
Normal 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
|
10
test/checker/test_equality_tapp.bolt
Normal file
10
test/checker/test_equality_tapp.bolt
Normal 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
|
||||||
|
|
24
test/checker/test_qualified_type_sigs.bolt
Normal file
24
test/checker/test_qualified_type_sigs.bolt
Normal 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)
|
6
test/checker/variable_mistyping.bolt
Normal file
6
test/checker/variable_mistyping.bolt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
# Testing variable typing
|
||||||
|
|
||||||
|
@expect_diagnostic 2010
|
||||||
|
let a: Int = "foo"
|
||||||
|
|
11
test/checker/wrong_return_type.bolt
Normal file
11
test/checker/wrong_return_type.bolt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
let wrong x.
|
||||||
|
if True.
|
||||||
|
return 1
|
||||||
|
elif False.
|
||||||
|
return 2
|
||||||
|
else.
|
||||||
|
@expect_diagnostic 2010
|
||||||
|
return "foo"
|
||||||
|
|
||||||
|
wrong 1
|
Loading…
Reference in a new issue