lib: fix conversion of hex char to int and add test
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 23 Jan 2014 14:49:00 +0000 (09:49 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 23 Jan 2014 18:15:23 +0000 (13:15 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/kernel.nit
tests/sav/test_hex.res [new file with mode: 0644]
tests/test_hex.nit [new file with mode: 0644]

index b9ce5e8..bdfd05c 100644 (file)
@@ -462,7 +462,7 @@ universal Char
                else if is_digit then
                        return self.ascii - '0'.ascii
                else
-                       return self.to_lower.ascii - ('a'.ascii + 10)
+                       return self.to_lower.ascii - 'a'.ascii + 10
                end
        end
 
diff --git a/tests/sav/test_hex.res b/tests/sav/test_hex.res
new file mode 100644 (file)
index 0000000..35580d6
--- /dev/null
@@ -0,0 +1,15 @@
+0
+1
+10
+10
+15
+2560
+256
+2748
+0
+1
+a
+10
+a00
+100
+abc
diff --git a/tests/test_hex.nit b/tests/test_hex.nit
new file mode 100644 (file)
index 0000000..fb259fa
--- /dev/null
@@ -0,0 +1,16 @@
+print "0".to_hex
+print "1".to_hex
+print "a".to_hex
+print "A".to_hex
+print "F".to_hex
+print "A00".to_hex
+print "0100".to_hex
+print "ABC".to_hex
+
+print 0.to_hex
+print 1.to_hex
+print 10.to_hex
+print 16.to_hex
+print 2560.to_hex
+print 256.to_hex
+print 2748.to_hex