CharacterFormatter implements IValueFormatter { @Override public Value valueOf(String value, Type type, Map<String, Object> options) { VirtualMachine vm = type.virtualMachine(); if (value == null) { return null; } if (value.length() == 3 && value.startsWith("'") && value.endsWith("'")) { return type.virtualMachine().mirrorOf(value.charAt(1)); } return vm.mirrorOf(value.charAt(0)); }  @Override String toString(Object value, Map<String, Object> options); @Override boolean acceptType(Type type, Map<String, Object> options); @Override Value valueOf(String value, Type type, Map<String, Object> options);  }
@Test public void testValueOf() throws Exception { Map<String, Object> options = formatter.getDefaultOptions(); Value charVar = getVM().mirrorOf('c'); Value newValue = formatter.valueOf("M", charVar.type(), options); assertTrue("should return char type", newValue instanceof CharValue); assertEquals("should return char 'M'", 'M', ((CharValue)newValue).value()); newValue = formatter.valueOf("'N'", charVar.type(), options); assertTrue("should return char type", newValue instanceof CharValue); assertEquals("should return char 'N'", 'N', ((CharValue)newValue).value()); newValue = formatter.valueOf("?", charVar.type(), options); assertTrue("should return char type", newValue instanceof CharValue); assertEquals("should return char '?", '?', ((CharValue)newValue).value()); newValue = formatter.valueOf("/", charVar.type(), options); assertTrue("should return char type", newValue instanceof CharValue); assertEquals("should return char '/'", '/', ((CharValue)newValue).value()); newValue = formatter.valueOf("'", charVar.type(), options); assertTrue("should return char type", newValue instanceof CharValue); assertEquals("should return char '", '\'', ((CharValue)newValue).value()); }