2
0
Bläddra i källkod

Merge pull request #303 from mkroehnert/hex

fix parsing of hex numbers and add tests for it
Nicolas Petton 12 år sedan
förälder
incheckning
44c8e48393
5 ändrade filer med 720 tillägg och 190 borttagningar
  1. 150 0
      js/Kernel-Tests.deploy.js
  2. 154 0
      js/Kernel-Tests.js
  3. 359 189
      js/parser.js
  4. 1 1
      js/parser.pegjs
  5. 56 0
      st/Kernel-Tests.st

+ 150 - 0
js/Kernel-Tests.deploy.js

@@ -1764,6 +1764,23 @@ return self}
 }),
 smalltalk.NumberTest);
 
+smalltalk.addMethod(
+"_testHexNumbers",
+smalltalk.method({
+selector: "testHexNumbers",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_assert_",[smalltalk.send((9),"__eq",[(9)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send((10),"_truncated",[]),"__eq",[(10)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send((11),"_truncated",[]),"__eq",[(11)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send((12),"_truncated",[]),"__eq",[(12)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send((13),"_truncated",[]),"__eq",[(13)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send((14),"_truncated",[]),"__eq",[(14)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send((15),"_truncated",[]),"__eq",[(15)])]);
+return self}
+}),
+smalltalk.NumberTest);
+
 smalltalk.addMethod(
 "_testIdentity",
 smalltalk.method({
@@ -1781,6 +1798,139 @@ return self}
 }),
 smalltalk.NumberTest);
 
+smalltalk.addMethod(
+"_testInvalidHexNumbers",
+smalltalk.method({
+selector: "testInvalidHexNumbers",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rG",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rg",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rH",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rh",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rI",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_ri",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rJ",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rj",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rK",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rk",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rL",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rl",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rM",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rm",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rN",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rn",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rO",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_ro",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rP",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rp",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rQ",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rq",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rR",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rr",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rS",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rs",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rT",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rt",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rU",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_ru",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rV",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rv",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rW",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rw",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rX",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rx",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rY",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_ry",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rZ",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((16),"_rz",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send((11259375),"_Z",[]);
+}),(smalltalk.MessageNotUnderstood || MessageNotUnderstood)]);
+return self}
+}),
+smalltalk.NumberTest);
+
 smalltalk.addMethod(
 "_testMinMax",
 smalltalk.method({

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 154 - 0
js/Kernel-Tests.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 359 - 189
js/parser.js


+ 1 - 1
js/parser.pegjs

@@ -23,7 +23,7 @@ number         = n:(hex / float / integer) {
                      return smalltalk.ValueNode._new()
                             ._value_(n)
                  }
-hex            = neg:[-]? "16r" num:[0-9a-zA-Z]+ {return parseInt((neg + num.join("")), 16)}
+hex            = neg:[-]? "16r" num:[0-9a-fA-F]+ {return parseInt((neg + num.join("")), 16)}
 float          = neg:[-]?int:[0-9]+ "." dec:[0-9]+ {return parseFloat((neg + int.join("") + "." + dec.join("")), 10)}
 integer        = neg:[-]?digits:[0-9]+ {return (parseInt(neg+digits.join(""), 10))}
 literalArray   = "#(" ws lits:(lit:literal ws {return lit._value()})* ws ")" {

+ 56 - 0
st/Kernel-Tests.st

@@ -931,6 +931,17 @@ testEquality
 	self deny: 0 = ''
 !
 
+testHexNumbers
+
+	self assert: 16r9 = 9.
+	self assert: 16rA truncated = 10.
+	self assert: 16rB truncated = 11.
+	self assert: 16rC truncated = 12.
+	self assert: 16rD truncated = 13.
+	self assert: 16rE truncated = 14.
+	self assert: 16rF truncated = 15
+!
+
 testIdentity
 	self assert: 1 == 1.
 	self assert: 0 == 0.
@@ -943,6 +954,51 @@ testIdentity
 	self deny: 1 == 2
 !
 
+testInvalidHexNumbers
+
+	self should: [16rG] raise: MessageNotUnderstood.
+   	self should: [16rg] raise: MessageNotUnderstood.
+	self should: [16rH] raise: MessageNotUnderstood.
+   	self should: [16rh] raise: MessageNotUnderstood.
+	self should: [16rI] raise: MessageNotUnderstood.
+   	self should: [16ri] raise: MessageNotUnderstood.
+	self should: [16rJ] raise: MessageNotUnderstood.
+   	self should: [16rj] raise: MessageNotUnderstood.
+	self should: [16rK] raise: MessageNotUnderstood.
+   	self should: [16rk] raise: MessageNotUnderstood.
+	self should: [16rL] raise: MessageNotUnderstood.
+   	self should: [16rl] raise: MessageNotUnderstood.
+	self should: [16rM] raise: MessageNotUnderstood.
+   	self should: [16rm] raise: MessageNotUnderstood.
+	self should: [16rN] raise: MessageNotUnderstood.
+   	self should: [16rn] raise: MessageNotUnderstood.
+	self should: [16rO] raise: MessageNotUnderstood.
+   	self should: [16ro] raise: MessageNotUnderstood.
+	self should: [16rP] raise: MessageNotUnderstood.
+   	self should: [16rp] raise: MessageNotUnderstood.
+	self should: [16rQ] raise: MessageNotUnderstood.
+   	self should: [16rq] raise: MessageNotUnderstood.
+	self should: [16rR] raise: MessageNotUnderstood.
+   	self should: [16rr] raise: MessageNotUnderstood.
+	self should: [16rS] raise: MessageNotUnderstood.
+   	self should: [16rs] raise: MessageNotUnderstood.
+	self should: [16rT] raise: MessageNotUnderstood.
+   	self should: [16rt] raise: MessageNotUnderstood.
+	self should: [16rU] raise: MessageNotUnderstood.
+   	self should: [16ru] raise: MessageNotUnderstood.
+	self should: [16rV] raise: MessageNotUnderstood.
+   	self should: [16rv] raise: MessageNotUnderstood.
+	self should: [16rW] raise: MessageNotUnderstood.
+   	self should: [16rw] raise: MessageNotUnderstood.
+	self should: [16rX] raise: MessageNotUnderstood.
+   	self should: [16rx] raise: MessageNotUnderstood.
+	self should: [16rY] raise: MessageNotUnderstood.
+   	self should: [16ry] raise: MessageNotUnderstood.
+	self should: [16rZ] raise: MessageNotUnderstood.
+   	self should: [16rz] raise: MessageNotUnderstood.
+    self should: [16rABcdEfZ] raise: MessageNotUnderstood.
+!
+
 testMinMax
 	
 	self assert: (2 max: 5) equals: 5.

Vissa filer visades inte eftersom för många filer har ändrats