// This is the behavior in Japanese @Test public void testProcessingInstruction() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[1]; wsphs[0] = new MockWSTextSegmentPlaceholder("<?xm-replace_text The Big Cheese?>", 3); Map<Integer, PHData> phmap = WSPlaceholderUtil.makePlaceholderMap(wsphs); final String parameterizedText = "For more information on {3}, please click here."; String x = WSPlaceholderUtil.replacePlaceholders(parameterizedText, phmap); assertEquals("For more information on <?xm-replace_text ws_id='3'?>, please click here.", x); String y = WSPlaceholderUtil.restorePlaceholders(x, phmap); assertEquals(parameterizedText, y); }
/* * Test the replacement logic in a more tricky case where an IMG tag is divided into two pieces at the ALT attribute * string. */ @Test public void testFragmentedImgTag() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[2]; wsphs[0] = new MockWSTextSegmentPlaceholder("<img alt=\"", 3); wsphs[1] = new MockWSTextSegmentPlaceholder("\" src=\"diagram.jpg\">", 4); Map<Integer, PHData> phmap = WSPlaceholderUtil.makePlaceholderMap(wsphs); final String parameterizedText = "Do you see this {3}alt test here{4} clearly?"; String x = WSPlaceholderUtil.replacePlaceholders(parameterizedText, phmap); assertEquals("Do you see this <img alt=\"alt test here\" src=\"diagram.jpg\"> clearly?", x); String y = WSPlaceholderUtil.restorePlaceholders(x, phmap); assertEquals(parameterizedText, y); }
/* * Test the replacement logic using the most basic, simple replacement, corresponding to the supposed original HTML * file: <br/> <pre> <html;gt;<body><p>Please click <a href="help.html>here<</a> for * help. </body></html;> </pre> This would generate three segments, and the second segment should appear * like: <pre> Please click {1}here{2} for help. </pre> */ @Test public void testSimpleReplacement() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[2]; wsphs[0] = new MockWSTextSegmentPlaceholder("<a href=\"help.html\">", 1); wsphs[1] = new MockWSTextSegmentPlaceholder("</a>", 2); Map<Integer, PHData> phmap = WSPlaceholderUtil.makePlaceholderMap(wsphs); final String parameterizedText = "Please click {1}here{2} for help."; String x = WSPlaceholderUtil.replacePlaceholders(parameterizedText, phmap); assertEquals("Please click <a ws_id='1'>here</a> for help.", x); String y = WSPlaceholderUtil.restorePlaceholders(x, phmap); assertEquals(parameterizedText, y); }
@Test public void testPairedTags() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[1]; wsphs[0] = new MockWSTextSegmentPlaceholder("<productname>The Big Cheese</productname>", 3); Map<Integer, PHData> phmap = WSPlaceholderUtil.makePlaceholderMap(wsphs); final String parameterizedText = "For more information on {3}, please click here."; String x = WSPlaceholderUtil.replacePlaceholders(parameterizedText, phmap); assertEquals( "For more information on <productname ws_id='3'>QFX0003</productname>, please click here.", x); String y = WSPlaceholderUtil.restorePlaceholders(x, phmap); assertEquals(parameterizedText, y); }
/* * Test the case where the order of the placeholders changes after translation. */ @Test public void testReordering() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[4]; wsphs[0] = new MockWSTextSegmentPlaceholder("<a href=\"dog.html\">", 5); wsphs[1] = new MockWSTextSegmentPlaceholder("</a>", 6); wsphs[2] = new MockWSTextSegmentPlaceholder("<a href=\"cat.html\">", 7); wsphs[3] = new MockWSTextSegmentPlaceholder("</a>", 8); Map<Integer, PHData> phmap = WSPlaceholderUtil.makePlaceholderMap(wsphs); final String parameterizedText = "A {5}cat{6} is chased by a {7}dog{8}"; String x = WSPlaceholderUtil.replacePlaceholders(parameterizedText, phmap); assertEquals("A <a ws_id='5'>cat</a> is chased by a <a ws_id='7'>dog</a>", x); String y = WSPlaceholderUtil.restorePlaceholders(x, phmap); assertEquals("A {5}cat{6} is chased by a {7}dog{8}", y); // Let's pretend the placeholders were re-ordered in translation... String z = WSPlaceholderUtil.restorePlaceholders( "A <a ws_id='7'>cat</a> is chased by a <a ws_id='5'>dog</a>", phmap); assertEquals("A {7}cat{8} is chased by a {5}dog{6}", z); }
@Test public void testReordering2() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[6]; wsphs[0] = new MockWSTextSegmentPlaceholder("<tt>", 1); wsphs[1] = new MockWSTextSegmentPlaceholder("</tt>", 2); wsphs[2] = new MockWSTextSegmentPlaceholder("<tt>", 3); wsphs[3] = new MockWSTextSegmentPlaceholder("</tt>", 4); wsphs[4] = new MockWSTextSegmentPlaceholder("<tt>", 5); wsphs[5] = new MockWSTextSegmentPlaceholder("</tt>", 6); Map<Integer, PHData> phmap = WSPlaceholderUtil.makePlaceholderMap(wsphs); final String parameterizedText = "A {1}cat{2} is {3}chased{4} by a {5}dog{6}"; String x = WSPlaceholderUtil.replacePlaceholders(parameterizedText, phmap); assertEquals( "A <tt ws_id='1'>cat</tt> is <tt ws_id='3'>chased</tt> by a <tt ws_id='5'>dog</tt>", x); String y = WSPlaceholderUtil.restorePlaceholders(x, phmap); assertEquals("A {1}cat{2} is {3}chased{4} by a {5}dog{6}", y); // Let's pretend the placeholders were re-ordered in translation... String z = WSPlaceholderUtil.restorePlaceholders( "A <tt ws_id='3'>chat</tt> is <tt ws_id='5'>chased</tt> by a <tt ws_id='1'>chien</tt>", phmap); assertEquals("A {3}chat{4} is {5}chased{6} by a {1}chien{2}", z); }
@Test public void testReordering3() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[6]; wsphs[0] = new MockWSTextSegmentPlaceholder("<tt>", 41); wsphs[1] = new MockWSTextSegmentPlaceholder("</tt>", 42); wsphs[2] = new MockWSTextSegmentPlaceholder("<tt>", 43); wsphs[3] = new MockWSTextSegmentPlaceholder("</tt>", 44); wsphs[4] = new MockWSTextSegmentPlaceholder("<tt>", 45); wsphs[5] = new MockWSTextSegmentPlaceholder("</tt>", 46); Map<Integer, PHData> phmap = WSPlaceholderUtil.makePlaceholderMap(wsphs); final String parameterizedText = "{41}--d{42} (the name), {43}--b{44} (the ID), and {45}--c{46} (the name)."; String x = WSPlaceholderUtil.replacePlaceholders(parameterizedText, phmap); assertEquals( "<tt ws_id='41'>--d</tt> (the name), <tt ws_id='43'>--b</tt> (the ID), and <tt ws_id='45'>--c</tt> (the name).", x); String z = WSPlaceholderUtil.restorePlaceholders( "<tt ws_id='41'>--d</tt> (le nom), <tt ws_id='43'>--b</tt> (l’ID) et <tt ws_id='45'>--c</tt> (le nom).", phmap); System.out.println(z); assertEquals("{41}--d{42} (le nom), {43}--b{44} (l’ID) et {45}--c{46} (le nom).", z); }