aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/yaml/snakeyaml/types/IntTagTest.java
blob: d75dad3224769b60d623b5ac0270cf5e9eaed9dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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"));
    }

}