@@ -1455,6 +1455,102 @@ public function testValidateInteger()
1455
1455
$ this ->assertTrue ($ v ->passes ());
1456
1456
}
1457
1457
1458
+ public function testValidateDecimal ()
1459
+ {
1460
+ $ trans = $ this ->getIlluminateArrayTranslator ();
1461
+ $ v = new Validator ($ trans , ['foo ' => 'asdad ' ], ['foo ' => 'Decimal:2,3 ' ]);
1462
+ $ this ->assertFalse ($ v ->passes ());
1463
+
1464
+ $ v = new Validator ($ trans , ['foo ' => '1.2345 ' ], ['foo ' => 'Decimal:2,3 ' ]);
1465
+ $ this ->assertFalse ($ v ->passes ());
1466
+
1467
+ $ v = new Validator ($ trans , ['foo ' => '1.234 ' ], ['foo ' => 'Decimal:2,3 ' ]);
1468
+ $ this ->assertTrue ($ v ->passes ());
1469
+
1470
+ $ v = new Validator ($ trans , ['foo ' => '-1.234 ' ], ['foo ' => 'Decimal:2,3 ' ]);
1471
+ $ this ->assertTrue ($ v ->passes ());
1472
+
1473
+ $ v = new Validator ($ trans , ['foo ' => '1.23 ' ], ['foo ' => 'Decimal:2,3 ' ]);
1474
+ $ this ->assertTrue ($ v ->passes ());
1475
+
1476
+ $ v = new Validator ($ trans , ['foo ' => '+1.23 ' ], ['foo ' => 'Decimal:2,3 ' ]);
1477
+ $ this ->assertTrue ($ v ->passes ());
1478
+
1479
+ $ v = new Validator ($ trans , ['foo ' => '1.2 ' ], ['foo ' => 'Decimal:2,3 ' ]);
1480
+ $ this ->assertFalse ($ v ->passes ());
1481
+
1482
+ $ v = new Validator ($ trans , ['foo ' => '1.23 ' ], ['foo ' => 'Decimal:2 ' ]);
1483
+ $ this ->assertTrue ($ v ->passes ());
1484
+
1485
+ $ v = new Validator ($ trans , ['foo ' => '-1.23 ' ], ['foo ' => 'Decimal:2 ' ]);
1486
+ $ this ->assertTrue ($ v ->passes ());
1487
+
1488
+ $ v = new Validator ($ trans , ['foo ' => '1.233 ' ], ['foo ' => 'Decimal:2 ' ]);
1489
+ $ this ->assertFalse ($ v ->passes ());
1490
+
1491
+ $ v = new Validator ($ trans , ['foo ' => '1.2 ' ], ['foo ' => 'Decimal:2 ' ]);
1492
+ $ this ->assertFalse ($ v ->passes ());
1493
+
1494
+ $ v = new Validator ($ trans , ['foo ' => '1 ' ], ['foo ' => 'Decimal:0,1 ' ]);
1495
+ $ this ->assertTrue ($ v ->passes ());
1496
+
1497
+ $ v = new Validator ($ trans , ['foo ' => '1.2 ' ], ['foo ' => 'Decimal:0,1 ' ]);
1498
+ $ this ->assertTrue ($ v ->passes ());
1499
+
1500
+ $ v = new Validator ($ trans , ['foo ' => '-1.2 ' ], ['foo ' => 'Decimal:0,1 ' ]);
1501
+ $ this ->assertTrue ($ v ->passes ());
1502
+
1503
+ $ v = new Validator ($ trans , ['foo ' => '1.23 ' ], ['foo ' => 'Decimal:0,1 ' ]);
1504
+ $ this ->assertFalse ($ v ->passes ());
1505
+
1506
+ $ v = new Validator ($ trans , ['foo ' => '1.8888888888 ' ], ['foo ' => 'Decimal:10 ' ]);
1507
+ $ this ->assertTrue ($ v ->passes ());
1508
+
1509
+ $ v = new Validator ($ trans , [
1510
+ // these are the same number
1511
+ 'decimal ' => '0.555 ' ,
1512
+ 'scientific ' => '5.55e-1 ' ,
1513
+ ], [
1514
+ 'decimal ' => 'Decimal:0,2 ' ,
1515
+ 'scientific ' => 'Decimal:0,2 ' ,
1516
+ ]);
1517
+ $ this ->assertSame (['decimal ' , 'scientific ' ], $ v ->errors ()->keys ());
1518
+
1519
+ $ v = new Validator ($ trans , [
1520
+ // these are the same number
1521
+ 'decimal ' => '0.555 ' ,
1522
+ 'scientific ' => '5.55e-1 ' ,
1523
+ ], [
1524
+ 'decimal ' => 'Decimal:0,3 ' ,
1525
+ 'scientific ' => 'Decimal:0,3 ' ,
1526
+ ]);
1527
+ $ this ->assertSame (['scientific ' ], $ v ->errors ()->keys ());
1528
+
1529
+ $ v = new Validator ($ trans , ['foo ' => '+ ' ], ['foo ' => 'Decimal:0,2 ' ]);
1530
+ $ this ->assertTrue ($ v ->fails ());
1531
+ $ v = new Validator ($ trans , ['foo ' => '- ' ], ['foo ' => 'Decimal:0,2 ' ]);
1532
+ $ this ->assertTrue ($ v ->fails ());
1533
+ $ v = new Validator ($ trans , ['foo ' => '10@12 ' ], ['foo ' => 'Decimal:0,2 ' ]);
1534
+ $ this ->assertTrue ($ v ->fails ());
1535
+
1536
+ $ v = new Validator ($ trans , ['foo ' => '+123 ' ], ['foo ' => 'Decimal:0,2 ' ]);
1537
+ $ this ->assertTrue ($ v ->passes ());
1538
+ $ v = new Validator ($ trans , ['foo ' => '-123 ' ], ['foo ' => 'Decimal:0,2 ' ]);
1539
+ $ this ->assertTrue ($ v ->passes ());
1540
+ $ v = new Validator ($ trans , ['foo ' => '+123. ' ], ['foo ' => 'Decimal:0,2 ' ]);
1541
+ $ this ->assertTrue ($ v ->passes ());
1542
+ $ v = new Validator ($ trans , ['foo ' => '-123. ' ], ['foo ' => 'Decimal:0,2 ' ]);
1543
+ $ this ->assertTrue ($ v ->passes ());
1544
+ $ v = new Validator ($ trans , ['foo ' => '123. ' ], ['foo ' => 'Decimal:0,2 ' ]);
1545
+ $ this ->assertTrue ($ v ->passes ());
1546
+ $ v = new Validator ($ trans , ['foo ' => '123. ' ], ['foo ' => 'Decimal:0,2 ' ]);
1547
+ $ this ->assertTrue ($ v ->passes ());
1548
+ $ v = new Validator ($ trans , ['foo ' => '123.34 ' ], ['foo ' => 'Decimal:0,2 ' ]);
1549
+ $ this ->assertTrue ($ v ->passes ());
1550
+ $ v = new Validator ($ trans , ['foo ' => '123.34 ' ], ['foo ' => 'Decimal:0,2 ' ]);
1551
+ $ this ->assertTrue ($ v ->passes ());
1552
+ }
1553
+
1458
1554
public function testValidateInt ()
1459
1555
{
1460
1556
$ trans = $ this ->getIlluminateArrayTranslator ();
0 commit comments