Skip to content

Commit

Permalink
Implement unit tests for Glob.globMatch (#12065)
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Friedmann <[email protected]>
  • Loading branch information
robinf95 committed Feb 1, 2024
1 parent 2f8d267 commit 758a388
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions libs/common/src/test/java/org/opensearch/common/GlobTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.common;

import org.opensearch.test.OpenSearchTestCase;

public class GlobTests extends OpenSearchTestCase {


public void testGlobMatchNoWildcard() {
assertTrue(Glob.globMatch("test", "test"));
assertFalse(Glob.globMatch("test", "testing"));
}


public void testGlobMatchWildcardAtBeginning() {
assertTrue(Glob.globMatch("*test", "thisisatest"));
assertFalse(Glob.globMatch("*test", "thisisatesting"));
}


public void testGlobMatchWildcardAtEnd() {
assertTrue(Glob.globMatch("test*", "testthisisa"));
assertFalse(Glob.globMatch("test*", "atestthisis"));
}


public void testGlobMatchWildcardAtMiddle() {
assertTrue(Glob.globMatch("test*ing", "testthisisaing"));
assertFalse(Glob.globMatch("test*ing", "testthisisa"));
}


public void testGlobMatchMultipleWildcards() {
assertTrue(Glob.globMatch("*test*", "thisisatesting"));
assertFalse(Glob.globMatch("*test*", "thisisatesing"));
}


public void testGlobMatchNullPattern() {
assertFalse(Glob.globMatch(null, "test"));
}


public void testGlobMatchNullString() {
assertFalse(Glob.globMatch("test", null));
}


public void testGlobMatchNullPatternAndString() {
assertFalse(Glob.globMatch(null, null));
}
}

0 comments on commit 758a388

Please sign in to comment.