Link Search Menu Expand Document

String Assertions

An assertion tool to verify String values.

  • GdUnitStringAssert

    Function Description
    is_null Verifies that the current value is null.
    is_not_null Verifies that the current value is not null.
    is_equal Verifies that the current String is equal to the given one.
    is_equal_ignoring_case Verifies that the current String is equal to the given one, ignoring case considerations.
    is_not_equal Verifies that the current String is not equal to the given one.
    is_not_equal_ignoring_case Verifies that the current String is not equal to the given one, ignoring case considerations.
    is_empty Verifies that the current String is empty, it has a length of 0.
    is_not_empty Verifies that the current String is not empty, it has a length of minimum 1.
    contains Verifies that the current String contains the given String.
    contains_ignoring_case Verifies that the current String does not contain the given String, ignoring case considerations.
    not_contains Verifies that the current String does not contain the given String.
    not_contains_ignoring_case Verifies that the current String does not contain the given String, ignoring case considerations.
    starts_with Verifies that the current String starts with the given prefix.
    ends_with Verifies that the current String ends with the given suffix.
    has_length Verifies that the current String has the expected length by used comparator.
  • IStringAssert

    Function Description
    IsNull Verifies that the current value is null.
    IsNotNull Verifies that the current value is not null.
    IsEqual Verifies that the current String is equal to the given one.
    IsEqualIgnoringCase Verifies that the current String is equal to the given one, ignoring case considerations.
    IsNotEqual Verifies that the current String is not equal to the given one.
    IsNotEqualIgnoringCase Verifies that the current String is not equal to the given one, ignoring case considerations.
    IsEmpty Verifies that the current String is empty, it has a length of 0.
    IsNotEmpty Verifies that the current String is not empty, it has a length of minimum 1.
    Contains Verifies that the current String contains the given String.
    ContainsIgnoringCase Verifies that the current String does not contain the given String, ignoring case considerations.
    NotContains Verifies that the current String does not contain the given String.
    NotContainsIgnoringCase Verifies that the current String does not contain the given String, ignoring case considerations.
    StartsWith Verifies that the current String starts with the given prefix.
    EndsWith Verifies that the current String ends with the given suffix.
    HasLength Verifies that the current String has the expected length by used comparator.

String Assert Examples

is_equal

Verifies that the current String is equal to the given one.

  •     func assert_str(<current>).is_equal(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a test message").is_equal("This is a test message")
    
        # this assertion fails because the 'Message' is writen camel case
        assert_str("This is a test message").is_equal("This is a test Message")
    
  •     public static IStringAssert AssertThat(<current>).IsEqual(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a test message").IsEqual("This is a test message");
    
        // this assertion fails because the 'Message' is writen camel case
        AssertThat("This is a test message").IsEqual("This is a test Message");
    

is_equal_ignoring_case

Verifies that the current String is equal to the given one, ignoring case considerations.

  •     func assert_str(<current>).is_equal_ignoring_case(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a test message").is_equal_ignoring_case("This is a test Message")
    
        # this assertion fails because 'test' is missing 
        assert_str("This is a test message").is_equal_ignoring_case("This is a Message")
    
  •     public static IStringAssert AssertThat(<current>).IsEqualIgnoringCase(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a test message").IsEqualIgnoringCase("This is a test Message")
    
        // this assertion fails because 'test' is missing 
        AssertThat("This is a test message").IsEqualIgnoringCase("This is a Message")
    

is_not_equal

Verifies that the current String is not equal to the given one.

  •     func assert_str(<current>).is_not_equal(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a test message").is_not_equal("This is a test Message")
    
        # this assertion fails because the values are equal
        assert_str("This is a test message").is_not_equal("This is a test message")
    
  •     public static IStringAssert AssertThat(<current>).IsNotEqual(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a test message").IsNotEqual("This is a test Message");
    
        // this assertion fails because the values are equal
        AssertThat("This is a test message").IsNotEqual("This is a test message");
    

is_not_equal_ignoring_case

Verifies that the current String is not equal to the given one, ignoring case considerations.

  •     func assert_str(<current>).is_not_equal_ignoring_case(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a test message").is_not_equal_ignoring_case("This is a Message")
    
        # this assertion fails because the values are equal ignoring camel case
        assert_str("This is a test message").is_not_equal_ignoring_case("This is a test Message")
    
  •     public static IStringAssert AssertThat(<current>).IsNotEqualIgnoringCase(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a test message").IsNotEqualIgnoringCase("This is a Message");
    
        // this assertion fails because the values are equal ignoring camel case
        AssertThat("This is a test message").IsNotEqualIgnoringCase("This is a test Message");
    

is_empty

Verifies that the current String is empty, it has a length of 0.

  •     func assert_str(<current>).is_empty() -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("").is_empty()
    
        # this assertion fails because the values contains a single space
        assert_str(" ").is_empty()
    
  •     public static IStringAssert AssertThat(<current>).IsEmpty()
    
        // this assertion succeeds
        AssertThat("").IsEmpty();
    
        // this assertion fails because the values contains a single space
        AssertThat(" ").IsEmpty();
    

is_not_empty

Verifies that the current String is not empty, it has a length of minimum 1.

  •     func assert_str(<current>).is_not_empty() -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str(" ").is_not_empty()
    
        # this assertion fails because the values empty (has size of 0 lenght)
        assert_str("").is_not_empty()
    
  •     public static IStringAssert AssertThat(<current>).IsNotEmpty()
    
        // this assertion succeeds
        AssertThat(" ").IsNotEmpty();
    
        // this assertion fails because the values empty (has size of 0 lenght)
        AssertThat("").IsNotEmpty();
    

contains

Verifies that the current String contains the given String.

  •     func assert_str(<current>).contains(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a String").contains("is")
    
        # this assertion fails
        assert_str("This is a String").contains("not")
    
  •     public static IStringAssert AssertThat(<current>).Contains(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a String").Contains("is");
    
        // this assertion fails
        AssertThat("This is a String").Contains("not");
    

contains_ignoring_case

Verifies that the current String does not contain the given String, ignoring case considerations.

  •     func assert_str(<current>).contains_ignoring_case(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a String").contains_ignoring_case("IS")
    
        # this assertion fails
        assert_str("This is a String").contains_ignoring_case("not")
    
  •     public static IStringAssert AssertThat(<current>).ContainsIgnoringCase(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a String").ContainsIgnoringCase("IS");
    
        // this assertion fails
        AssertThat("This is a String").ContainsIgnoringCase("not");
    

not_contains

Verifies that the current String does not contain the given String.

  •     func assert_str(<current>).not_contains(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a String").not_contains("not")
    
        # this assertion fails
        assert_str("This is a String").not_contains("is")
    
  •     public static IStringAssert AssertThat(<current>).NotContains(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a String").NotContains("not");
    
        // this assertion fails
        AssertThat("This is a String").NotContains("is");
    

not_contains_ignoring_case

Verifies that the current String does not contain the given String, ignoring case considerations.

  •     func assert_str(<current>).not_contains_ignoring_case(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a String").not_contains_ignoring_case("Not")
    
        # this assertion fails
        assert_str("This is a String").not_contains_ignoring_case("IS")
    
  •     public static IStringAssert AssertThat(<current>).NotContainsIgnoringCase(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a String").NotContainsIgnoringCase("Not");
    
        // this assertion fails
        AssertThat("This is a String").NotContainsIgnoringCase("IS");
    

starts_with

Verifies that the current String starts with the given prefix.

  •     func assert_str(<current>).starts_with(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a String").starts_with("This is")
    
        # this assertion fails
        assert_str("This is a String").starts_with("a String")
    
  •     public static IStringAssert AssertThat(<current>).StartsWith(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a String").StartsWith("This is");
    
        // this assertion fails
        AssertThat("This is a String").StartsWith("a String");
    

ends_with

Verifies that the current String ends with the given suffix.

  •     func assert_str(<current>).ends_with(<expected>) -> GdUnitStringAssert
    
        # this assertion succeeds
        assert_str("This is a String").ends_with("a String")
    
        # this assertion fails
        assert_str("This is a String").ends_with("a Str")
    
  •     public static IStringAssert AssertThat(<current>).EndsWith(<expected>)
    
        // this assertion succeeds
        AssertThat("This is a String").EndsWith("a String");
    
        // this assertion fails
        AssertThat("This is a String").EndsWith("a Str");
    

has_length

Verifies that the current String has the expected length by used [[comparator|Asserts#GdUnit Comparator]].

  •     func assert_str(<current>).has_length(<expected>, <comparator> (EXACTLY)) -> GdUnitStringAssert
    
        # this assertion succeeds because the current String has 22 characters 
        assert_str("This is a test message").has_length(22)
        assert_str("This is a test message").has_length(23, Comparator.LESS_THAN)
        assert_str("This is a test message").has_length(22, Comparator.LESS_EQUAL)
        assert_str("This is a test message").has_length(21, Comparator.GREATER_THAN)
        assert_str("This is a test message").has_length(21, Comparator.GREATER_EQUAL)
    
        # this assertion fails because the current String has 22 characters and not 23
        assert_str("This is a test message").has_length(23)
        assert_str("This is a test message").has_length(22, Comparator.LESS_THAN)
        assert_str("This is a test message").has_length(21, Comparator.LESS_EQUAL) 
        assert_str("This is a test message").has_length(22, Comparator.GREATER_THAN)
        assert_str("This is a test message").has_length(23, Comparator.GREATER_EQUAL)
    
  •     public static IStringAssert AssertThat(<current>).HasLength(<expected>, <comparator> (// EQUAL is default))
    
        // this assertion succeeds because the current String has 22 characters 
        AssertThat("This is a test message").HasLength(22);
        AssertThat("This is a test message").HasLength(23, Compare.LESS_THAN);
        AssertThat("This is a test message").HasLength(22, Compare.LESS_EQUAL);
        AssertThat("This is a test message").HasLength(21, Compare.GREATER_THAN);
        AssertThat("This is a test message").HasLength(21, Compare.GREATER_EQUAL);
    
        // this assertion fails because the current String has 22 characters and not 23
        AssertThat("This is a test message").HasLength(23);
        AssertThat("This is a test message").HasLength(22, Compare.LESS_THAN);
        AssertThat("This is a test message").HasLength(21, Compare.LESS_EQUAL); 
        AssertThat("This is a test message").HasLength(22, Compare.GREATER_THAN);
        AssertThat("This is a test message").HasLength(23, Compare.GREATER_EQUAL);
    

Copyright © 2021-2022 Mike Schulze. Distributed by an MIT license.