on master help sign in
Merge pull request #651 from maxsnew/char
6870d58Evan Czaplicki
libraries/Native/Char.js+6−4
@@ -4,6 +4,8 @@ Elm.Native.Char.make = function(elm) {
4 elm.Native.Char = elm.Native.Char || {};
4 elm.Native.Char = elm.Native.Char || {};
5 if (elm.Native.Char.values) return elm.Native.Char.values;
5 if (elm.Native.Char.values) return elm.Native.Char.values;
6
6
7+ var Utils = Elm.Native.Utils.make(elm);
8+
7 function isBetween(lo,hi) { return function(chr) {
9 function isBetween(lo,hi) { return function(chr) {
8 var c = chr.charCodeAt(0);
10 var c = chr.charCodeAt(0);
9 return lo <= c && c <= hi;
11 return lo <= c && c <= hi;
@@ -16,10 +18,10 @@ Elm.Native.Char.make = function(elm) {
16 return elm.Native.Char.values = {
18 return elm.Native.Char.values = {
17 fromCode : function(c) { return String.fromCharCode(c); },
19 fromCode : function(c) { return String.fromCharCode(c); },
18 toCode : function(c) { return c.toUpperCase().charCodeAt(0); },
20 toCode : function(c) { return c.toUpperCase().charCodeAt(0); },
19− toUpper : function(c) { return c.toUpperCase(); },
21+ toUpper : function(c) { return Utils.chr(c.toUpperCase()); },
20− toLower : function(c) { return c.toLowerCase(); },
22+ toLower : function(c) { return Utils.chr(c.toLowerCase()); },
21− toLocaleUpper : function(c) { return c.toLocaleUpperCase(); },
23+ toLocaleUpper : function(c) { return Utils.chr(c.toLocaleUpperCase()); },
22− toLocaleLower : function(c) { return c.toLocaleLowerCase(); },
24+ toLocaleLower : function(c) { return Utils.chr(c.toLocaleLowerCase()); },
23 isLower : isBetween('a'.charCodeAt(0),'z'.charCodeAt(0)),
25 isLower : isBetween('a'.charCodeAt(0),'z'.charCodeAt(0)),
24 isUpper : isBetween('A'.charCodeAt(0),'Z'.charCodeAt(0)),
26 isUpper : isBetween('A'.charCodeAt(0),'Z'.charCodeAt(0)),
25 isDigit : isDigit,
27 isDigit : isDigit,
tests/libraries/LibraryTest.hs+4−2
@@ -43,7 +43,9 @@ main = do
43runCmd :: String -> [String] -> IO ()
43runCmd :: String -> [String] -> IO ()
44runCmd cmd args = do
44runCmd cmd args = do
45 putStrLn (cmd ++ " " ++ unwords args)
45 putStrLn (cmd ++ " " ++ unwords args)
46− (exitCode, _stdout, stderr) <- readProcessWithExitCode cmd args ""
46+ (exitCode, stdout, stderr) <- readProcessWithExitCode cmd args ""
47+ putStr stdout
48+ putStr stderr
47 case exitCode of
49 case exitCode of
48 ExitSuccess -> return ()
50 ExitSuccess -> return ()
49− ExitFailure _ -> error stderr
51+ ExitFailure _ -> exitWith exitCode
tests/libraries/Test.elm+2
@@ -10,6 +10,7 @@ import IO.Runner (Request, Response)
10import IO.Runner as Run
10import IO.Runner as Run
11
11
12import Test.Array as Array
12import Test.Array as Array
13+import Test.Char as Char
13import Test.Dict as Dict
14import Test.Dict as Dict
14import Test.Equality as Equality
15import Test.Equality as Equality
15import Test.List as List
16import Test.List as List
@@ -20,6 +21,7 @@ import Test.Trampoline as Trampoline
20tests : Test
21tests : Test
21tests = suite "Elm Standard Library Tests"
22tests = suite "Elm Standard Library Tests"
22 [ Array.tests
23 [ Array.tests
24+ , Char.tests
23 , Dict.tests
25 , Dict.tests
24 , Equality.tests
26 , Equality.tests
25 , List.tests
27 , 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+ ]