コード例 #1
0
  public void testSystemProperties() {
    Format fmt =
        new Format(
            "You are {0}, the parent of your home is {1} and you run Java version {2}"); //$NON-NLS-1$
    fmt.addValueHolder(new PropertyRef<String>(String.class, "user.name")); // $NON-NLS-1$
    Replace rpl1 = new Replace();
    rpl1.addMatch(new Replace.Match(Pattern.quote("\\"), "/", false)); // $NON-NLS-1$ //$NON-NLS-2$
    rpl1.addValueHolder(new PropertyRef<String>(String.class, "user.home")); // $NON-NLS-1$
    Replace rpl2 = new Replace();
    rpl2.addMatch(new Replace.Match("^(.*)/[^/]+$", "$1", false)); // $NON-NLS-1$ //$NON-NLS-2$
    rpl2.addValueHolder(rpl1);
    fmt.addValueHolder(rpl2);
    fmt.addValueHolder(new PropertyRef<String>(String.class, "java.version")); // $NON-NLS-1$

    IProperties<String> props = BMProperties.getSystemProperties();
    String result = fmt.getValue(props);
    String expected =
        "You are "
            + props.get("user.name")
            + ", the parent of your home is " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            + (new File(props.get("user.home"))).getParent().replace('\\', '/')
            + " and you run Java version " //$NON-NLS-1$ //$NON-NLS-2$
            + props.get("java.version"); // $NON-NLS-1$

    log(result);
    assertEquals(expected, result);
  }
コード例 #2
0
  public void testSplit() {
    ValueHolder<String> value = new Constant<String>("buckminster.tigris.org:/cvs"); // $NON-NLS-1$
    String fmtString =
        "First \"{0}\", second \"{1}\", third \"{2}\", and fourth \"{3}\""; //$NON-NLS-1$

    Format fmt = new Format(fmtString);
    Split split = new Split("\\.|:", 0); // $NON-NLS-1$
    split.addValueHolder(value);
    fmt.addValueHolder(split);

    String expected =
        new MessageFormat(fmtString)
            .format(
                new String[] {
                  "buckminster", //$NON-NLS-1$
                  "tigris",
                  "org",
                  "/cvs"
                }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    IProperties<String> props = BMProperties.getSystemProperties();
    String result = fmt.getValue(props);
    log(result);
    assertEquals(expected, result);
  }
コード例 #3
0
  public void testExpressions() {
    ValueHolder<String> cvsRoot =
        new Constant<String>(":pserver:${user.name}@buckminster.tigris.org:/cvs"); // $NON-NLS-1$
    String fmtString =
        "First \"{0}\", second \"{1}\", third \"{2}\", and fourth \"{3}\""; //$NON-NLS-1$

    Format fmt = new Format(fmtString);
    Split split = new Split(":|@", 0); // $NON-NLS-1$
    Replace rpl = new Replace();
    rpl.addMatch(new Replace.Match("^:(.*)$", "$1", false)); // $NON-NLS-1$ //$NON-NLS-2$
    rpl.addValueHolder(cvsRoot);
    split.addValueHolder(rpl);
    fmt.addValueHolder(split);

    String expected =
        new MessageFormat(fmtString)
            .format(
                new String[] {
                  "pserver", //$NON-NLS-1$
                  System.getProperty("user.name"),
                  "buckminster.tigris.org",
                  "/cvs"
                }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    IProperties<String> props = BMProperties.getSystemProperties();
    String result = fmt.getValue(props);
    log(result);
    assertEquals(expected, result);
  }