aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/yaml/snakeyaml/types/IntTagTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/yaml/snakeyaml/types/IntTagTest.java')
-rw-r--r--src/test/java/org/yaml/snakeyaml/types/IntTagTest.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/java/org/yaml/snakeyaml/types/IntTagTest.java b/src/test/java/org/yaml/snakeyaml/types/IntTagTest.java
new file mode 100644
index 00000000..d75dad32
--- /dev/null
+++ b/src/test/java/org/yaml/snakeyaml/types/IntTagTest.java
@@ -0,0 +1,55 @@
+/*
+ * See LICENSE file in distribution for copyright and licensing information.
+ */
+package org.yaml.snakeyaml.types;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @see http://yaml.org/type/int.html
+ */
+public class IntTagTest extends AbstractTest {
+
+ public void testInt() throws IOException {
+ assertEquals(new Integer(685230), getMapValue("canonical: 685230", "canonical"));
+ assertEquals(new Integer(685230), getMapValue("number: 685_230", "number"));
+ assertEquals(new Integer(685230), getMapValue("decimal: +685230", "decimal"));
+ assertEquals(new Integer(-685230), getMapValue("number: -685230", "number"));
+ assertEquals(new Integer(685230), getMapValue("octal: 02472256", "octal"));
+ assertEquals(new Integer(685230), getMapValue("hexadecimal: 0x_0A_74_AE", "hexadecimal"));
+ assertEquals(new Integer(685230), getMapValue("binary: 0b1010_0111_0100_1010_1110",
+ "binary"));
+ assertEquals(new Integer(685230), getMapValue("sexagesimal: 190:20:30", "sexagesimal"));
+ assertEquals(new Integer(0), load("0"));
+ assertEquals(new Integer(0), load("-0"));
+ assertEquals(new Integer(0), load("+0"));
+ assertEquals(Integer.MIN_VALUE, load(dump(Integer.MIN_VALUE)));
+ assertEquals(Integer.MAX_VALUE, load(dump(Integer.MAX_VALUE)));
+ }
+
+ public void testBigInt() throws IOException {
+ assertEquals(new Long(922337203685477580L), load("922337203685477580"));
+ assertEquals(new BigInteger("9223372036854775809999999999"),
+ load("9223372036854775809999999999"));
+ assertEquals(Long.MIN_VALUE, load("-9223372036854775808"));
+ }
+
+ public void testIntShorthand() throws IOException {
+ assertEquals(new Integer(1), getMapValue("number: !!int 1", "number"));
+ }
+
+ public void testIntTag() throws IOException {
+ assertEquals(new Integer(1), getMapValue("number: !<tag:yaml.org,2002:int> 1", "number"));
+ }
+
+ public void testIntOut() throws IOException {
+ Map<String, Integer> map = new HashMap<String, Integer>();
+ map.put("number", new Integer(1));
+ String output = dump(map);
+ assertTrue(output.contains("number: 1"));
+ }
+
+}