Skip to content

TestClassContains - #2694

Merged
xushiwei merged 1 commit into
goplus:mainfrom
xushiwei:q
Mar 30, 2026
Merged

xushiwei merged 1 commit into
goplus:mainfrom
xushiwei:q

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

@codecov

codecov Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.12%. Comparing base (db05c03) to head (12e36e3).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2694   +/-   ##
=======================================
  Coverage   94.12%   94.12%           
=======================================
  Files          32       32           
  Lines       10053    10053           
=======================================
  Hits         9462     9462           
  Misses        421      421           
  Partials      170      170           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fennoai

fennoai Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Good test addition — table-driven structure is clean and covers the core contract well (exact token matching, substring rejection, whitespace handling around spaces).

One notable gap: ClassContains only treats ASCII space (' ') as a delimiter, but the HTML spec defines class tokens as separated by any ASCII whitespace (\t, \n, \r, \f, space). Consider adding test cases for non-space whitespace to document the intended behavior — whether that's a known limitation or a bug to fix.

Comment thread dql/html/html_test.go
classAttr: "foo bar baz",
classVal: "qux",
want: false,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a few more edge cases to pin down the contract:

  1. Tab/newline as separator — classAttr: "foo\tbar" with classVal: "bar". The current ClassContains impl only splits on space, so this returns false. A test case would document whether that's intentional or a bug (HTML spec treats \t, \n, \r, \f as valid whitespace separators).

  2. classVal with embedded space — classAttr: "foo bar baz", classVal: "foo bar" → should be false (class names can't contain spaces).

  3. All-whitespace classAttr — classAttr: " ", classVal: "foo" → should be false.

@xushiwei
xushiwei merged commit ffda7bf into goplus:main Mar 30, 2026
11 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a comprehensive test suite for the ClassContains function, covering basic matching, substring rejections, and whitespace handling. Review feedback recommends improving the specificity of suffix substring tests and expanding coverage to include additional HTML-compliant whitespace characters, case sensitivity, and invalid class values.

Comment thread dql/html/html_test.go
Comment on lines +67 to +72
{
name: "rejects suffix substring",
classAttr: "param-required required",
classVal: "required-extra",
want: false,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test case named "rejects suffix substring" currently checks a value that is longer than the class in the attribute (e.g., "required-extra" vs "required"). It would be more robust to also include a test for a true suffix substring (e.g., "class" in "my-class") and rename the existing one to something more descriptive like "rejects longer value".

Suggested change
{
name: "rejects suffix substring",
classAttr: "param-required required",
classVal: "required-extra",
want: false,
},
{
name: "rejects suffix substring",
classAttr: "my-class",
classVal: "class",
want: false,
},
{
name: "rejects longer value",
classAttr: "param-required required",
classVal: "required-extra",
want: false,
},

Comment thread dql/html/html_test.go
classVal: "qux",
want: false,
},
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding test cases for other HTML-compliant whitespace characters (tabs, newlines, form feeds, and carriage returns), case sensitivity, and classVal containing spaces. These are important edge cases for robust HTML class matching according to the specification.

		{
			name:      "matches with other whitespace",
			classAttr: "foo\tbar\nbaz\rfuz\fqux",
			classVal:  "baz",
			want:      true,
		},
		{
			name:      "case sensitive match",
			classAttr: "Foo",
			classVal:  "foo",
			want:      false,
		},
		{
			name:      "rejects classVal with spaces",
			classAttr: "foo bar baz",
			classVal:  "foo bar",
			want:      false,
		},
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant