-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
171 additions
and
23 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
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
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,59 @@ | ||
package glint | ||
|
||
import ( | ||
"sync/atomic" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDocument_mountUnmount(t *testing.T) { | ||
require := require.New(t) | ||
|
||
// Create our doc | ||
r := &StringRenderer{} | ||
d := New() | ||
d.SetRenderer(r) | ||
|
||
// Add our component | ||
var c testMount | ||
d.Append(&c) | ||
require.Equal(uint32(0), atomic.LoadUint32(&c.mount)) | ||
require.Equal(uint32(0), atomic.LoadUint32(&c.unmount)) | ||
|
||
// Render once | ||
d.RenderFrame() | ||
require.Equal(uint32(1), atomic.LoadUint32(&c.mount)) | ||
require.Equal(uint32(0), atomic.LoadUint32(&c.unmount)) | ||
|
||
// Render again | ||
d.RenderFrame() | ||
require.Equal(uint32(1), atomic.LoadUint32(&c.mount)) | ||
require.Equal(uint32(0), atomic.LoadUint32(&c.unmount)) | ||
|
||
// Remove the old components | ||
d.Set() | ||
d.RenderFrame() | ||
require.Equal(uint32(1), atomic.LoadUint32(&c.mount)) | ||
require.Equal(uint32(1), atomic.LoadUint32(&c.unmount)) | ||
|
||
// Render again | ||
d.RenderFrame() | ||
require.Equal(uint32(1), atomic.LoadUint32(&c.mount)) | ||
require.Equal(uint32(1), atomic.LoadUint32(&c.unmount)) | ||
} | ||
|
||
type testMount struct { | ||
terminalComponent | ||
|
||
mount uint32 | ||
unmount uint32 | ||
} | ||
|
||
func (c *testMount) Mount() { atomic.AddUint32(&c.mount, 1) } | ||
func (c *testMount) Unmount() { atomic.AddUint32(&c.unmount, 1) } | ||
|
||
var ( | ||
_ Component = (*testMount)(nil) | ||
_ ComponentMounter = (*testMount)(nil) | ||
) |
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
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