on master help sign in
Merge pull request #388 from JanBessai/StrLenRegressionTest

StrLen regression test

commita97a08b2d91556173b3bfc4d1afa8cbf3b313902 authorEdwin Brady <edwin.brady@gmail.com> dateThu 11 Jul 2013, 13:04 (13 years ago) parent5606f7feff62f4
7 files changed+60
idris.cabal+3 src/IRTS/CodegenC.hs+2 test/Makefile+1 test/README+2 test/reg020/expected+7 test/reg020/reg020.idr+41 test/reg020/run+4
idris.cabal+3
@@ -135,6 +135,9 @@ Extra-source-files: lib/Makefile lib/*.idr lib/Prelude/*.idr
135135 test/reg019/run
136136 test/reg019/*.idr
137137 test/reg019/expected
138+ test/reg020/run
139+ test/reg020/*.idr
140+ test/reg020/expected
138141 test/test001/run
139142 test/test001/*.idr
140143 test/test001/expected
src/IRTS/CodegenC.hs+2
@@ -364,6 +364,8 @@ doOp v (LSRem (ATInt (ITFixed ty))) [x, y] = bitOp v "SRem" ty [x, y]
364364
365365doOp v (LSExt (ITFixed from) ITBig) [x]
366366 = v ++ "MKBIGSI(vm, (" ++ signedTy from ++ ")" ++ creg x ++ "->info.bits" ++ show (nativeTyWidth from) ++ ")"
367+doOp v (LZExt ITNative ITBig) [x]
368+ = v ++ "MKBIGSI(vm, GETINT(" ++ creg x ++ "))"
367369doOp v (LSExt ITNative (ITFixed to)) [x]
368370 = v ++ "idris_b" ++ show (nativeTyWidth to) ++ "const(vm, GETINT(" ++ creg x ++ "))"
369371doOp v (LSExt ITChar (ITFixed to)) [x]
test/Makefile+1
@@ -25,6 +25,7 @@ test_js:
2525 @perl ./runtest.pl reg017 --codegen node
2626 @perl ./runtest.pl reg018 --codegen node
2727 @perl ./runtest.pl reg019 --codegen node
28+ @perl ./runtest.pl reg020 --codegen node
2829 @perl ./runtest.pl test001 --codegen node
2930 @perl ./runtest.pl test002 --codegen node
3031 @perl ./runtest.pl test003 --codegen node
test/README+2
@@ -29,3 +29,5 @@ Tests:
2929027: class constraints in using block
3030
3131regxxx: various regression tests
32+reg020: working strlen
33+
test/reg020/expectednew file+7
@@ -0,0 +1,7 @@
1+length of: '' is: 0
2+length of: 'hello world!' is: 12
3+length of: ' ' is: 1
4+length of: ' ' is: 1
5+length of: '
6+' is: 1
7+length of all matches sum of all lengths: True
test/reg020/reg020.idrnew file+41
@@ -0,0 +1,41 @@
1+module Main
2+
3+emptyString : String
4+emptyString = ""
5+
6+helloWorld : String
7+helloWorld = "hello world!"
8+
9+spaceOnly : String
10+spaceOnly = " "
11+
12+tabOnly : String
13+tabOnly = "\t"
14+
15+linebreakOnly : String
16+linebreakOnly = "\n"
17+
18+all : Vect String 5
19+all =
20+ [ emptyString
21+ , helloWorld
22+ , spaceOnly
23+ , tabOnly
24+ , linebreakOnly
25+ ]
26+
27+lengthAll : Nat
28+lengthAll = Strings.length $ foldl (++) (head all) (tail all)
29+
30+sumOfAllLengths : Nat
31+sumOfAllLengths = foldl (\ l, s => l + (Strings.length s)) (Strings.length $ head all) (tail all)
32+
33+
34+main : IO ()
35+main = do putStrLn $ "length of: '" ++ emptyString ++ "' is: " ++ (show $ length emptyString)
36+ putStrLn $ "length of: '" ++ helloWorld ++ "' is: " ++ (show $ length helloWorld)
37+ putStrLn $ "length of: '" ++ spaceOnly ++ "' is: " ++ (show $ length spaceOnly)
38+ putStrLn $ "length of: '" ++ tabOnly ++ "' is: " ++ (show $ length tabOnly)
39+ putStrLn $ "length of: '" ++ linebreakOnly ++ "' is: " ++ (show $ length linebreakOnly)
40+ putStrLn $ "length of all matches sum of all lengths: " ++ (show $ lengthAll == sumOfAllLengths)
41+
test/reg020/runnew file+4
@@ -0,0 +1,4 @@
1+#!/bin/bash
2+idris $@ reg020.idr -o reg020
3+./reg020
4+rm -f reg020 *.ibc