-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from liamg/liamg-add-disable-option
Add func to disable all formatting output
- Loading branch information
Showing
3 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package tml | ||
|
||
import "sync" | ||
|
||
var disableFormatting bool | ||
var formattingLock sync.RWMutex | ||
|
||
func DisableFormatting() { | ||
formattingLock.Lock() | ||
defer formattingLock.Unlock() | ||
disableFormatting = true | ||
} | ||
|
||
func EnableFormatting() { | ||
formattingLock.Lock() | ||
defer formattingLock.Unlock() | ||
disableFormatting = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package tml | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseWithFormattingDisabled(t *testing.T) { | ||
DisableFormatting() | ||
defer EnableFormatting() | ||
output, err := Parse("plain <red>red <bold>bold red</bold></red> plain <green>green</green> plain") | ||
require.Nil(t, err) | ||
assert.Equal(t, "plain red bold red plain green plain", output) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters