@Test
public void testEscapeGenerator()
{

    JSONConfig cfg = new JSONConfig().setUseECMA6(false).setEscapeNonAscii(true)
                                     .setBadCharacterPolicy(JSONConfig.ESCAPE);
    StringBuilder buf = new StringBuilder();
    Set<Character> singles = new HashSet<>(Arrays.asList('\b','\t','\n','\f','\r'));
    Random rand = new Random();
    int bound = Character.MAX_CODE_POINT+1;
    int min = Character.MIN_SUPPLEMENTARY_CODE_POINT;
    for ( int i = 0; i < 4096; i++ ){
        int cp;
        do{
            cp = rand.nextInt(bound);
        }while ( cp >= ' ' && cp < 128 );
        buf.setLength(0);
        buf.appendCodePoint(cp);
        String result;
        if ( cp < min ){
            if ( cp < 0xF && singles.contains((char)cp) ){
                result = '"' + StringProcessor.getEscape((char)cp) + '"';
            }else{
                result = '"' + String.format("\\u%04X", cp) + '"';
            }
        }else{
            int high = Character.highSurrogate(cp);
            int low = Character.lowSurrogate(cp);
            result = '"' + String.format("\\u%04X\\u%04X", high, low) + '"';
        }
        String json = JSONUtil.toJSON(buf, cfg);
        assertThat(json, is(result));
    }
}