PropertyType { public PropertyValue<T> parse(String value) { return parser.parse(name, value); } PropertyType(String name, String description, PropertyValueParser<T> parser, Set<String> possibleValues);  PropertyType(String name, String description, PropertyValueParser<T> parser, String... possibleValues); static Set<PropertyType<?>> standardTypes(); String getDescription(); String getName(); Set<String> getPossibleValues(); String normalizeIfNeeded(String value); PropertyValue<T> parse(String value); @Override String toString(); static final PropertyType<String> charset; static final PropertyType<EndOfLineValue> end_of_line; static final PropertyType<Integer> indent_size; static final PropertyType<IndentStyleValue> indent_style; static final PropertyType<Boolean> insert_final_newline; static final PropertyType<Integer> max_line_length; static final PropertyType<Boolean> root; static final PropertyType<Integer> tab_width; static final PropertyType<Boolean> trim_trailing_whitespace; static final String unset; }
@Test public void charset() { Assert.assertEquals(PropertyValue.valid("utf-8", "utf-8"), PropertyType.charset.parse("utf-8")); Assert.assertEquals(PropertyValue.valid("UTF-8", "UTF-8"), PropertyType.charset.parse("UTF-8")); Assert.assertTrue(PropertyType.charset.parse("").isValid()); Assert.assertTrue(PropertyType.charset.parse("foo").isValid()); Assert.assertTrue(PropertyType.charset.parse(null).isValid()); }
@Test public void eol() { Assert.assertEquals(PropertyValue.valid("cr", EndOfLineValue.cr), PropertyType.end_of_line.parse("cr")); Assert.assertEquals(PropertyValue.valid("CR", EndOfLineValue.cr), PropertyType.end_of_line.parse("CR")); Assert.assertEquals(PropertyValue.valid("Cr", EndOfLineValue.cr), PropertyType.end_of_line.parse("Cr")); Assert.assertEquals(PropertyValue.valid("CrLf", EndOfLineValue.crlf), PropertyType.end_of_line.parse("CrLf")); Assert.assertEquals(PropertyValue.valid("lf", EndOfLineValue.lf), PropertyType.end_of_line.parse("lf")); Assert.assertFalse(PropertyType.end_of_line.parse("").isValid()); Assert.assertFalse(PropertyType.end_of_line.parse("foo").isValid()); Assert.assertFalse(PropertyType.end_of_line.parse(null).isValid()); }
@Test public void indentSize() { Assert.assertEquals(PropertyValue.valid("1", 1), PropertyType.indent_size.parse("1")); Assert.assertEquals(PropertyValue.valid("tab", null), PropertyType.indent_size.parse("tab")); Assert.assertFalse(PropertyType.indent_size.parse("").isValid()); Assert.assertFalse(PropertyType.indent_size.parse("0").isValid()); Assert.assertFalse(PropertyType.indent_size.parse("-1").isValid()); Assert.assertTrue(PropertyType.indent_size.parse("tab").isValid()); Assert.assertFalse(PropertyType.indent_size.parse(null).isValid()); }
@Test public void indentStyle() { Assert.assertEquals(PropertyValue.valid("space", IndentStyleValue.space), PropertyType.indent_style.parse("space")); Assert.assertEquals(PropertyValue.valid("SPACE", IndentStyleValue.space), PropertyType.indent_style.parse("SPACE")); Assert.assertEquals(PropertyValue.valid("SpAcE", IndentStyleValue.space), PropertyType.indent_style.parse("SpAcE")); Assert.assertEquals(PropertyValue.valid("tab", IndentStyleValue.tab), PropertyType.indent_style.parse("tab")); Assert.assertFalse(PropertyType.indent_style.parse("").isValid()); Assert.assertFalse(PropertyType.indent_style.parse("foo").isValid()); Assert.assertFalse(PropertyType.indent_style.parse(null).isValid()); }
@Test public void maxLineLength() { Assert.assertEquals(PropertyValue.valid("1", 1), PropertyType.max_line_length.parse("1")); Assert.assertEquals(PropertyValue.valid("off", null), PropertyType.max_line_length.parse("off")); Assert.assertFalse(PropertyType.max_line_length.parse("").isValid()); Assert.assertFalse(PropertyType.max_line_length.parse("0").isValid()); Assert.assertFalse(PropertyType.max_line_length.parse("-1").isValid()); Assert.assertTrue(PropertyType.max_line_length.parse("off").isValid()); Assert.assertFalse(PropertyType.max_line_length.parse(null).isValid()); }
@Test public void tabWidth() { Assert.assertEquals(PropertyValue.valid("1", 1), PropertyType.tab_width.parse("1")); Assert.assertFalse(PropertyType.tab_width.parse("").isValid()); Assert.assertFalse(PropertyType.tab_width.parse("0").isValid()); Assert.assertFalse(PropertyType.tab_width.parse("-1").isValid()); Assert.assertFalse(PropertyType.tab_width.parse("tab").isValid()); Assert.assertFalse(PropertyType.tab_width.parse(null).isValid()); }