private void testForMatchingText(String text, ProgramLocation location) {

		assertNotNull(location);

		if (location instanceof FunctionSignatureFieldLocation) {
			FunctionSignatureFieldLocation fLoc = ((FunctionSignatureFieldLocation) location);
			Pattern regexp = UserSearchUtils.createSearchPattern(text, false);
			Matcher matcher = regexp.matcher(fLoc.getSignature());
			assertTrue(matcher.find());
		}
		else if (location instanceof VariableNameFieldLocation) {
			VariableNameFieldLocation vLoc = (VariableNameFieldLocation) location;
			assertTrue(vLoc.getName().indexOf(text) >= 0);
			assertEquals(0, vLoc.getCharOffset());
		}
		else if (location instanceof OperandFieldLocation) {
			OperandFieldLocation opLoc = ((OperandFieldLocation) location);
			assertTrue(opLoc.getOperandRepresentation().indexOf(text) >= 0);
		}
		else if (location instanceof EolCommentFieldLocation) {
			EolCommentFieldLocation eLoc = (EolCommentFieldLocation) location;
			assertEquals(CommentType.EOL, eLoc.getCommentType());
			String[] comment = eLoc.getComment();
			for (String element : comment) {
				if (element.indexOf(text) >= 0) {
					return;
				}
			}
			Assert.fail(
				"Did not find matching text in the EOL comment at address " + eLoc.getAddress());
		}
		else if (location instanceof AutomaticCommentFieldLocation) {
			AutomaticCommentFieldLocation eLoc = (AutomaticCommentFieldLocation) location;
			assertEquals(CommentType.EOL, eLoc.getCommentType());
			String[] comment = eLoc.getComment();
			for (String element : comment) {
				if (element.indexOf(text) >= 0) {
					return;
				}
			}
			Assert.fail("Did not find matching text in the automatic comment at address " +
				eLoc.getAddress());
		}
		else {
			Assert.fail("Unexpected ProgramLocation type: " + location);
		}
	}
Test the searcher that searches fields in the Code Browser
Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/ListingDisplaySearcherTest.java