Skip to content

Conversation

savioxavier
Copy link
Owner

Description

Closes #1

This pull requests adds basic unit tests for this package

Tests currently included are:

TestBasicLink
TestColorLink
TestColorsPackageLink
TestBoldLink
TestItalicsLink
TestItalicsBoldLink
TestColorItalicsBoldLink

More tests will be added soon

There's a main handler function called testAll that tests both types of test in one go, without the need to check for SupportsHyperlink() everytime using logic statements. A basic structure of a test is as follows:

func TestBasicLink(t *testing.T) {
	input := termlink.Link("Hello", "https://google.com")
	expectedHyperlink := "\x1b]8;;https://google.com\aHello\x1b]8;;\a\x1b[m"
	expectedNoHyperlink := "Hello (\u200Bhttps://google.com)\u001b[m"

	testAll(input, expectedHyperlink, expectedNoHyperlink)(t)
}

Run the tests using go test -v. Please ensure the tests are run both in hyperlink and non-hyperlink supported terminals. I had used Zsh on WSL with Windows Terminal for the hyperlink tests and Zsh on WSL with VSCode for the non-hyperlink tests.

@savioxavier savioxavier merged commit 75edd9c into master Jun 4, 2022
@savioxavier savioxavier deleted the testing branch June 4, 2022 14:47
@savioxavier
Copy link
Owner Author

Just make sure you run the tests locally, not sure why it fails in the workflow.

The results from the workflow tests look similar to Git Bash's, maybe that's the case?

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.

Write unit tests
1 participant