public ATerm parsePattern(final String pattern) throws ParseError { return parse(pattern); }
@Override public ATerm make(final String trm) { return parse(trm); }
@Override public ATerm make(final String pattern, final List<Object> args) { return make(parse(pattern), args); }
private ATerm makeBigDummyTerm(final int x) { final byte[] b = new byte[x]; for (int i = 2; i < b.length - 1; i++) b[i] = 'x'; b[0] = 'a'; b[1] = '('; b[b.length - 1] = ')'; final String s = new String(b); return _pureFactory.parse(s); }
@Test public void testWriting() throws Exception { // A term ATerm input = _pureFactory.parse("line(box(rect(2), square(4, 3)), circle(6))"); byte[] expectedResult = new byte[] { 1, 2, 4, 108, 105, 110, 101, 1, 2, 3, 98, 111, 120, 1, 1, 4, 114, 101, 99, 116, 2, 2, 1, 2, 6, 115, 113, 117, 97, 114, 101, 2, 4, 2, 3, 1, 1, 6, 99, 105, 114, 99, 108, 101, 2, 6 }; write(input, expectedResult); // A openllet.shared.hash term input = _pureFactory.parse("line(line(), line())"); expectedResult = new byte[] { 1, 2, 4, 108, 105, 110, 101, 1, 0, 4, 108, 105, 110, 101, -128, 1 }; write(input, expectedResult); // A term with signature sharing input = _pureFactory.parse("line(line(0), line(1))"); expectedResult = new byte[] { 1, 2, 4, 108, 105, 110, 101, 1, 1, 4, 108, 105, 110, 101, 2, 0, 65, 1, 2, 1 }; write(input, expectedResult); // // A term with annotations // input = _pureFactory.parse("line(10, 11{childAnno}){termAnno{annoOfAnno}}"); // expectedResult = new byte[] { 17, 2, 4, 108, 105, 110, 101, 2, 10, 18, 11, 4, 1, 1, 0, 9, 99, 104, 105, 108, 100, 65, 110, 110, 111, 4, 1, 17, 0, 8, 116, 101, 114, 109, 65, 110, 110, 111, 4, 1, 1, 0, 10, 97, 110, 110, 111, 79, 102, 65, 110, 110, 111 }; // write(input, expectedResult); // Signed integer input = _pureFactory.parse("integer(-1)"); expectedResult = new byte[] { 1, 1, 7, 105, 110, 116, 101, 103, 101, 114, 2, -1, -1, -1, -1, 15 }; write(input, expectedResult); // Signed double input = _pureFactory.parse("real(-1.0)"); expectedResult = new byte[] { 1, 1, 4, 114, 101, 97, 108, 3, 0, 0, 0, 0, 0, 0, -16, -65 }; write(input, expectedResult); }
@Test public void testReading() { // A term byte[] input = new byte[] { 1, 2, 4, 108, 105, 110, 101, 1, 2, 3, 98, 111, 120, 1, 1, 4, 114, 101, 99, 116, 2, 2, 1, 2, 6, 115, 113, 117, 97, 114, 101, 2, 4, 2, 3, 1, 1, 6, 99, 105, 114, 99, 108, 101, 2, 6 }; ATerm expectedResult = _pureFactory.parse("line(box(rect(2), square(4, 3)), circle(6))"); read(input, expectedResult); // A openllet.shared.hash term input = new byte[] { 1, 2, 4, 108, 105, 110, 101, 1, 0, 4, 108, 105, 110, 101, -128, 1 }; expectedResult = _pureFactory.parse("line(line(), line())"); read(input, expectedResult); // A term with signature sharing input = new byte[] { 1, 2, 4, 108, 105, 110, 101, 1, 1, 4, 108, 105, 110, 101, 2, 0, 65, 1, 2, 1 }; expectedResult = _pureFactory.parse("line(line(0), line(1))"); read(input, expectedResult); // // A term with annotations // input = new byte[] { 17, 2, 4, 108, 105, 110, 101, 2, 10, 18, 11, 4, 1, 1, 0, 9, 99, 104, 105, 108, 100, 65, 110, 110, 111, 4, 1, 17, 0, 8, 116, 101, 114, 109, 65, 110, 110, 111, 4, 1, 1, 0, 10, 97, 110, 110, 111, 79, 102, 65, 110, 110, 111 }; // expectedResult = _pureFactory.parse("line(10, 11{childAnno}){termAnno{annoOfAnno}}"); // read(input, expectedResult); // Signed integer input = new byte[] { 1, 1, 7, 105, 110, 116, 101, 103, 101, 114, 2, -1, -1, -1, -1, 15 }; expectedResult = _pureFactory.parse("integer(-1)"); read(input, expectedResult); // Signed double input = new byte[] { 1, 1, 4, 114, 101, 97, 108, 3, 0, 0, 0, 0, 0, 0, -16, -65 }; expectedResult = _pureFactory.parse("real(-1.0)"); read(input, expectedResult); }