void () { MessageFormatUtil.MessageFormatResult result = MessageFormatUtil.checkFormat("{0}12345''''6789{0, number{, #.00"); Assert.assertFalse(result.valid()); List<MessageFormatUtil.MessageFormatError> errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNCLOSED_BRACE_PLACEHOLDER, errors.get(0).errorType()); Assert.assertEquals(16, errors.get(0).fromIndex()); Assert.assertEquals(17, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat("{0}12345'6789{0, number, #.00}"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNPAIRED_QUOTE, errors.get(0).errorType()); Assert.assertEquals(8, errors.get(0).fromIndex()); Assert.assertEquals(9, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat("{0}12345'{0, number, #.00}"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNPAIRED_QUOTE, errors.get(0).errorType()); Assert.assertEquals(8, errors.get(0).fromIndex()); Assert.assertEquals(9, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat("' 123"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNPAIRED_QUOTE, errors.get(0).errorType()); Assert.assertEquals(0, errors.get(0).fromIndex()); Assert.assertEquals(1, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat("'' 123'"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNPAIRED_QUOTE, errors.get(0).errorType()); Assert.assertEquals(6, errors.get(0).fromIndex()); Assert.assertEquals(7, errors.get(0).toIndex()); } @Test public void testChoiceSimple() { MessageFormatUtil.MessageHolder result = MessageFormatUtil.parseMessageHolder( "{0} choice: {0, choice,-1#'''' - 2 quotes|0<more|2<''1{0}'' '''' - 1 quote|3≤{0, number, '#'.00}}"); Assert.assertTrue(result.getErrors().isEmpty()); Assert.assertTrue(ContainerUtil.exists(result.getParts(), t -> t.getText().equals("1{0} ' - 1 quote"))); Assert.assertTrue(ContainerUtil.exists(result.getParts(), t -> t.getText().equals("'' - 2 quotes"))); Assert.assertTrue(ContainerUtil.exists(result.getParts(), t -> t.getText().equals("{0,number, #.00}") && t.getParsedType() == MessageFormatUtil.MessageFormatParsedType.FORMAT_ELEMENT)); result = MessageFormatUtil.parseMessageHolder( "nested choice: {0, choice,0# inner'{0, choice,1#test1|2#test2}'|3# inner 2}}"); Assert.assertTrue(result.getErrors().isEmpty()); Assert.assertTrue(ContainerUtil.exists(result.getParts(), t -> t.getText().equals("test1"))); Assert.assertTrue(ContainerUtil.exists(result.getParts(), t -> t.getText().equals("test2"))); Assert.assertTrue(ContainerUtil.exists(result.getParts(), t -> t.getText().equals(" inner 2"))); MessageFormatUtil.MessageFormatResult formatResult = MessageFormatUtil.checkFormat("nested choice: {0, choice, 0#1}"); Assert.assertTrue(formatResult.valid()); formatResult = MessageFormatUtil.checkFormat("{0} choice: {0, choice,-1#'''' - 2 quotes|0<more|2<'''1'''}"); Assert.assertTrue(formatResult.valid()); } @Test public void testChoiceCompileError() { MessageFormatUtil.MessageFormatResult result = MessageFormatUtil.checkFormat( "{0} choice: {0, choice,-1#'''' - 2 quotes|0<more|2<''{0}'' '''' - 1 quotes|3#{0, number, #.00}}"); Assert.assertFalse(result.valid()); List<MessageFormatUtil.MessageFormatError> errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.SELECTOR_NOT_FOUND, errors.get(0).errorType()); Assert.assertEquals(91, errors.get(0).fromIndex()); Assert.assertEquals(92, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat( "{0}'' choice: {0, choice,0<more|wrong<wrong}"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.INCORRECT_CHOICE_SELECTOR, errors.get(0).errorType()); Assert.assertEquals(34, errors.get(0).fromIndex()); Assert.assertEquals(39, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat( "{0}'' choice: {0, choice,0<more|-1<wrong}"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.INCORRECT_ORDER_CHOICE_SELECTOR, errors.get(0).errorType()); Assert.assertEquals(34, errors.get(0).fromIndex()); Assert.assertEquals(36, errors.get(0).toIndex()); } @Test public void testChoiceNestedWarning() { MessageFormatUtil.MessageFormatResult result = MessageFormatUtil.checkFormat( "{0}'' choice: {0, choice,0<more|1<''{0}''}"); Assert.assertFalse(result.valid()); List<MessageFormatUtil.MessageFormatError> errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.QUOTED_PLACEHOLDER, errors.get(0).errorType()); Assert.assertEquals(38, errors.get(0).fromIndex()); Assert.assertEquals(41, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat( "{0}'' choice: {0, choice,0<more|1<''{''}"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNMATCHED_BRACE, errors.get(0).errorType()); Assert.assertEquals(14, errors.get(0).fromIndex()); Assert.assertEquals(15, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat( "nested choice: {0, choice,0# inner'''{0, choice,1#test1|2#test2}'|3#1}}"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(34, errors.get(0).fromIndex()); Assert.assertEquals(37, errors.get(0).toIndex()); } @Test public void testRange() { MessageFormatUtil.MessageFormatResult result = MessageFormatUtil.checkFormat("{0, wrong}"); Assert.assertFalse(result.valid()); List<MessageFormatUtil.MessageFormatError> errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNKNOWN_FORMAT_TYPE, errors.get(0).errorType()); Assert.assertEquals(3, errors.get(0).fromIndex()); Assert.assertEquals(9, errors.get(0).toIndex()); result = MessageFormatUtil.checkFormat("{0, wrong,}"); Assert.assertFalse(result.valid()); errors = result.errors(); Assert.assertEquals(1, errors.size()); Assert.assertEquals(MessageFormatUtil.MessageFormatErrorType.UNKNOWN_FORMAT_TYPE, errors.get(0).errorType()); Assert.assertEquals(3, errors.get(0).fromIndex()); Assert.assertEquals(9, errors.get(0).toIndex()); } @Test public void testChoiceIncorrectOrder() { MessageFormatUtil.MessageFormatResult result = MessageFormatUtil.checkFormat("{0, choice,0#0|0<1}"); Assert.assertTrue(result.valid()); } }