UNPKG

4.3 kBJavaScriptView Raw
1/*
2 Terminal Kit
3
4 Copyright (c) 2009 - 2020 Cédric Ronvel
5
6 The MIT License (MIT)
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25*/
26
27"use strict" ;
28
29
30
31var termkit = require( '../lib/termkit.js' ) ;
32var term = termkit.terminal ;
33var ScreenBuffer = termkit.ScreenBuffer ;
34var Rect = termkit.Rect ;
35
36
37
38describe( "ScreenBuffer.Rect" , function() {
39
40 it( "Rect.create( Terminal )" , function() {
41
42 expect( Rect.create( term ) ).to.be.like( {
43 xmin: 1 ,
44 ymin: 1 ,
45 xmax: term.width ,
46 ymax: term.height ,
47 width: term.width ,
48 height: term.height ,
49 isNull: false
50 } ) ;
51
52 } ) ;
53
54 it( "Rect.create( xmin , ymin , xmax , ymax )" , function() {
55
56 expect( Rect.create( 1 , 2 , 3 , 4 ) ).to.be.like( {
57 xmin: 1 ,
58 ymin: 2 ,
59 xmax: 3 ,
60 ymax: 4 ,
61 width: 3 ,
62 height: 3 ,
63 isNull: false
64 } ) ;
65
66 } ) ;
67
68 it( ".clip() should adjust accordingly" , function() {
69
70 var srcRect , dstRect ;
71
72 dstRect = Rect.create( { xmin: 0 , ymin: 20 , xmax: 25 , ymax: 45 , isNull: false } ) ;
73 srcRect = Rect.create( { xmin: 10 , ymin: 10 , xmax: 30 , ymax: 40 , isNull: false } ) ;
74 srcRect.clip( dstRect , 0 , 0 , true ) ;
75
76 expect( dstRect ).to.be.like( { xmin: 10, ymin: 20, xmax: 25, ymax: 40 , width: 16 , height: 21 , isNull: false } ) ;
77 expect( srcRect ).to.be.like( { xmin: 10, ymin: 20, xmax: 25, ymax: 40 , width: 16 , height: 21 , isNull: false } ) ;
78
79
80 dstRect = Rect.create( { xmin: 0 , ymin: 20 , xmax: 25 , ymax: 45 } ) ;
81 srcRect = Rect.create( { xmin: 10 , ymin: 10 , xmax: 30 , ymax: 40 } ) ;
82 srcRect.clip( dstRect , 5 , 0 , true ) ;
83
84 expect( dstRect ).to.be.like( { xmin: 15, ymin: 20, xmax: 25, ymax: 40 , width: 11 , height: 21 , isNull: false } ) ;
85 expect( srcRect ).to.be.like( { xmin: 10, ymin: 20, xmax: 20, ymax: 40 , width: 11 , height: 21 , isNull: false } ) ;
86
87
88 dstRect = Rect.create( { xmin: 0 , ymin: 20 , xmax: 25 , ymax: 45 } ) ;
89 srcRect = Rect.create( { xmin: 10 , ymin: 10 , xmax: 30 , ymax: 40 } ) ;
90 srcRect.clip( dstRect , -8 , 0 , true ) ;
91
92 expect( dstRect ).to.be.like( { xmin: 2, ymin: 20, xmax: 22, ymax: 40 , width: 21 , height: 21 , isNull: false } ) ;
93 expect( srcRect ).to.be.like( { xmin: 10, ymin: 20, xmax: 30, ymax: 40 , width: 21 , height: 21 , isNull: false } ) ;
94
95
96 dstRect = Rect.create( { xmin: 0 , ymin: 20 , xmax: 25 , ymax: 45 } ) ;
97 srcRect = Rect.create( { xmin: 10 , ymin: 10 , xmax: 30 , ymax: 40 } ) ;
98 srcRect.clip( dstRect , -31 , 0 , true ) ;
99
100 expect( dstRect.isNull ).to.be( true ) ;
101 expect( srcRect.isNull ).to.be( true ) ;
102
103
104 dstRect = Rect.create( { xmin: 0 , ymin: 20 , xmax: 25 , ymax: 45 } ) ;
105 srcRect = Rect.create( { xmin: 10 , ymin: 10 , xmax: 30 , ymax: 40 } ) ;
106 srcRect.clip( dstRect , -8 , 5 , true ) ;
107
108 expect( dstRect ).to.be.like( { xmin: 2, ymin: 20, xmax: 22, ymax: 45 , width: 21 , height: 26 , isNull: false } ) ;
109 expect( srcRect ).to.be.like( { xmin: 10, ymin: 15, xmax: 30, ymax: 40 , width: 21 , height: 26 , isNull: false } ) ;
110
111
112 dstRect = Rect.create( { xmin: 0 , ymin: 20 , xmax: 25 , ymax: 45 } ) ;
113 srcRect = Rect.create( { xmin: 10 , ymin: 10 , xmax: 30 , ymax: 40 } ) ;
114 srcRect.clip( dstRect , 0 , -21 , true ) ;
115
116 expect( dstRect.isNull ).to.be( true ) ;
117 expect( srcRect.isNull ).to.be( true ) ;
118 } ) ;
119} ) ;
120
121
122