1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | "use strict" ;
|
28 |
|
29 |
|
30 |
|
31 | var termkit = require( '../lib/termkit.js' ) ;
|
32 | var term = termkit.terminal ;
|
33 | var ScreenBuffer = termkit.ScreenBuffer ;
|
34 | var Rect = termkit.Rect ;
|
35 |
|
36 |
|
37 |
|
38 | describe( "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 |
|