/*
   * def test_replace
   *   assert_equal 'b b b b', @filters.replace("a a a a", 'a', 'b')
   *   assert_equal 'b a a a', @filters.replace_first("a a a a", 'a', 'b')
   *   assert_template_result 'b a a a', "{{ 'a a a a' | replace_first: 'a', 'b' }}"
   * end
   */
  @Test
  public void applyOriginalTest() {

    Filter filter = Filter.getFilter("replace_first");

    assertThat(filter.apply("a a a a", "a", "b"), is((Object) "b a a a"));
    assertThat(Template.parse("{{ 'a a a a' | replace_first: 'a', 'b' }}").render(), is("b a a a"));
  }
Exemple #2
0
  /*
   * def test_first_last
   *   assert_equal 1, @filters.first([1,2,3])
   *   assert_equal 3, @filters.last([1,2,3])
   *   assert_equal nil, @filters.first([])
   *   assert_equal nil, @filters.last([])
   * end
   */
  @Test
  public void applyOriginalTest() {

    Filter filter = Filter.getFilter("last");

    assertThat(filter.apply(new Integer[] {1, 2, 3}), is((Object) "3"));
    assertThat(filter.apply(new Integer[] {}), is((Object) null));
  }
  /*
   * def test_truncatewords
   *   assert_equal 'one two three', @filters.truncatewords('one two three', 4)
   *   assert_equal 'one two...', @filters.truncatewords('one two three', 2)
   *   assert_equal 'one two three', @filters.truncatewords('one two three')
   *   assert_equal 'Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”...',
   *                 @filters.truncatewords('Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.', 15)
   * end
   */
  @Test
  public void applyOriginalTest() {

    final Filter filter = Filter.getFilter("truncatewords");

    assertThat(filter.apply("one two three", 4), is((Object) "one two three"));
    assertThat(filter.apply("one two three", 2), is((Object) "one two..."));
    assertThat(filter.apply("one two three", 3), is((Object) "one two three"));
    assertThat(
        filter.apply(
            "Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.",
            15),
        is(
            (Object)
                "Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”..."));
  }