on master help sign in
Merge pull request #651 from maxsnew/char

Fix Broken Char Ops and Print More when Testing

commit6870d581d8301c0e160906054b89a39e4d74444a authorEvan Czaplicki <info@elm-lang.org> dateWed 11 Jun 2014, 16:00 (12 years ago) parent0bc1f4b141580f
4 files changed+27−6
libraries/Native/Char.js+6−4 tests/libraries/LibraryTest.hs+4−2 tests/libraries/Test.elm+2 tests/libraries/Test/Char.elm+15
libraries/Native/Char.js+6−4
@@ -4,6 +4,8 @@ Elm.Native.Char.make = function(elm) {
44 elm.Native.Char = elm.Native.Char || {};
55 if (elm.Native.Char.values) return elm.Native.Char.values;
66
7+ var Utils = Elm.Native.Utils.make(elm);
8+
79 function isBetween(lo,hi) { return function(chr) {
810 var c = chr.charCodeAt(0);
911 return lo <= c && c <= hi;
@@ -16,10 +18,10 @@ Elm.Native.Char.make = function(elm) {
1618 return elm.Native.Char.values = {
1719 fromCode : function(c) { return String.fromCharCode(c); },
1820 toCode : function(c) { return c.toUpperCase().charCodeAt(0); },
19− toUpper : function(c) { return c.toUpperCase(); },
20− toLower : function(c) { return c.toLowerCase(); },
21− toLocaleUpper : function(c) { return c.toLocaleUpperCase(); },
22− toLocaleLower : function(c) { return c.toLocaleLowerCase(); },
21+ toUpper : function(c) { return Utils.chr(c.toUpperCase()); },
22+ toLower : function(c) { return Utils.chr(c.toLowerCase()); },
23+ toLocaleUpper : function(c) { return Utils.chr(c.toLocaleUpperCase()); },
24+ toLocaleLower : function(c) { return Utils.chr(c.toLocaleLowerCase()); },
2325 isLower : isBetween('a'.charCodeAt(0),'z'.charCodeAt(0)),
2426 isUpper : isBetween('A'.charCodeAt(0),'Z'.charCodeAt(0)),
2527 isDigit : isDigit,
tests/libraries/LibraryTest.hs+4−2
@@ -43,7 +43,9 @@ main = do
4343runCmd :: String -> [String] -> IO ()
4444runCmd cmd args = do
4545 putStrLn (cmd ++ " " ++ unwords args)
46− (exitCode, _stdout, stderr) <- readProcessWithExitCode cmd args ""
46+ (exitCode, stdout, stderr) <- readProcessWithExitCode cmd args ""
47+ putStr stdout
48+ putStr stderr
4749 case exitCode of
4850 ExitSuccess -> return ()
49− ExitFailure _ -> error stderr
51+ ExitFailure _ -> exitWith exitCode
tests/libraries/Test.elm+2
@@ -10,6 +10,7 @@ import IO.Runner (Request, Response)
1010import IO.Runner as Run
1111
1212import Test.Array as Array
13+import Test.Char as Char
1314import Test.Dict as Dict
1415import Test.Equality as Equality
1516import Test.List as List
@@ -20,6 +21,7 @@ import Test.Trampoline as Trampoline
2021tests : Test
2122tests = suite "Elm Standard Library Tests"
2223 [ Array.tests
24+ , Char.tests
2325 , Dict.tests
2426 , Equality.tests
2527 , List.tests
tests/libraries/Test/Char.elmnew file+15
@@ -0,0 +1,15 @@
1+module Test.Char (tests) where
2+
3+import Char
4+
5+import ElmTest.Assertion (..)
6+import ElmTest.Test (..)
7+
8+tests : Test
9+tests =
10+ suite "Char"
11+ [ test "toUpper" <| assertEqual 'C' <| Char.toUpper 'c'
12+ , test "toLower" <| assertEqual 'c' <| Char.toLower 'C'
13+ , test "toLocaleUpper" <| assertEqual 'C' <| Char.toLocaleUpper 'c'
14+ , test "toLocaleLower" <| assertEqual 'c' <| Char.toLocaleLower 'C'
15+ ]