From 42a8993c9356a8a150ff25dd350a0e8408a91b16 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 28 Feb 2002 23:12:27 +0000 Subject: [PATCH] Added code to test the new MessageBundle recursive escaped composed translation facilities. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1078 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- tests/rsrc/i18n/messages.properties | 8 +++ .../threerings/util/MessageBundleTest.java | 60 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/rsrc/i18n/messages.properties create mode 100644 tests/src/java/com/threerings/util/MessageBundleTest.java diff --git a/tests/rsrc/i18n/messages.properties b/tests/rsrc/i18n/messages.properties new file mode 100644 index 000000000..f74c65868 --- /dev/null +++ b/tests/rsrc/i18n/messages.properties @@ -0,0 +1,8 @@ +# +# $Id: messages.properties,v 1.1 2002/02/28 23:12:27 mdb Exp $ +# +# Test localization properties file + +m.foo = Foo arg one is ''{0}'' and two is ''{1}''. +m.biff = Biff arg one is ''{0}'' and two is ''{1}''. +m.meta = Meta arg one is ''{0}'' and two is ''{1}''. diff --git a/tests/src/java/com/threerings/util/MessageBundleTest.java b/tests/src/java/com/threerings/util/MessageBundleTest.java new file mode 100644 index 000000000..b24f98a5c --- /dev/null +++ b/tests/src/java/com/threerings/util/MessageBundleTest.java @@ -0,0 +1,60 @@ +// +// $Id: MessageBundleTest.java,v 1.1 2002/02/28 23:12:27 mdb Exp $ + +package com.threerings.util; + +import java.util.ResourceBundle; + +import junit.framework.Test; +import junit.framework.TestCase; + +/** + * Tests the {@link MessageBundle} class. + */ +public class MessageBundleTest extends TestCase +{ + public MessageBundleTest () + { + super(MessageBundleTest.class.getName()); + } + + public void runTest () + { + try { + ResourceBundle rbundle = + ResourceBundle.getBundle("rsrc.i18n.messages"); + MessageBundle bundle = new MessageBundle("test", rbundle); + + String key1 = MessageBundle.compose("m.foo", + MessageBundle.taint("bar"), + MessageBundle.taint("baz")); + String key2 = MessageBundle.compose("m.biff", + MessageBundle.taint("beep"), + MessageBundle.taint("boop")); + String key = MessageBundle.compose("m.meta", key1, key2); + + String output = bundle.xlate(key); + if (!OUTPUT.equals(output)) { + fail("xlate failed: " + output); + } + + } catch (Exception e) { + fail("Test failed: " + e); + } + } + + public static Test suite () + { + return new MessageBundleTest(); + } + + public static void main (String[] args) + { + MessageBundleTest test = new MessageBundleTest(); + test.runTest(); + } + + protected static final String OUTPUT = + "Meta arg one is 'Foo arg one is 'bar' and two is 'baz'.' and " + + "two is 'Biff arg one is 'beep' and two is 'boop'.'."; +}