1
1
'use strict' ;
2
+ const fs = require ( 'fs' ) ;
2
3
const path = require ( 'path' ) ;
3
4
4
5
const assert = require ( 'chai' ) . assert ;
5
6
const rewire = require ( 'rewire' ) ;
6
7
8
+ const th = require ( './helper' ) ;
9
+
7
10
describe ( 'file' , function ( ) {
8
11
let file ;
9
12
@@ -14,7 +17,8 @@ describe('file', function() {
14
17
describe ( '#dirAndFiles' , function ( ) {
15
18
const HOME = path . join ( __dirname , '..' ) ;
16
19
17
- it ( 'should ok' , function ( ) {
20
+ it ( 'should ok on linux' , function ( ) {
21
+ if ( file . isWindows ( ) ) this . skip ( ) ;
18
22
process . env . HOME = '/home/skygragon' ;
19
23
20
24
assert . equal ( file . userHomeDir ( ) , '/home/skygragon' ) ;
@@ -23,10 +27,18 @@ describe('file', function() {
23
27
assert . equal ( file . cacheFile ( 'xxx' ) , '/home/skygragon/.lc/leetcode/cache/xxx.json' ) ;
24
28
assert . equal ( file . configFile ( ) , '/home/skygragon/.lc/config.json' ) ;
25
29
assert . equal ( file . name ( '/home/skygragon/.lc/leetcode/cache/xxx.json' ) , 'xxx' ) ;
30
+ } ) ;
26
31
32
+ it ( 'should ok on windows' , function ( ) {
33
+ if ( ! file . isWindows ( ) ) this . skip ( ) ;
27
34
process . env . HOME = '' ;
28
35
process . env . USERPROFILE = 'C:\\Users\\skygragon' ;
29
36
assert . equal ( file . userHomeDir ( ) , 'C:\\Users\\skygragon' ) ;
37
+ assert . equal ( file . homeDir ( ) , 'C:\\Users\\skygragon\\.lc' ) ;
38
+ assert . equal ( file . cacheDir ( ) , 'C:\\Users\\skygragon\\.lc\\leetcode\\cache' ) ;
39
+ assert . equal ( file . cacheFile ( 'xxx' ) , 'C:\\Users\\skygragon\\.lc\\leetcode\\cache\\xxx.json' ) ;
40
+ assert . equal ( file . configFile ( ) , 'C:\\Users\\skygragon\\.lc\\config.json' ) ;
41
+ assert . equal ( file . name ( 'C:\\Users\\skygragon\\.lc\\leetcode\\cache\\xxx.json' ) , 'xxx' ) ;
30
42
} ) ;
31
43
32
44
it ( 'should codeDir ok' , function ( ) {
@@ -98,5 +110,42 @@ describe('file', function() {
98
110
assert . equal ( meta . id , '222' ) ;
99
111
assert . equal ( meta . lang , 'python3' ) ;
100
112
} ) ;
113
+
114
+ it ( 'should fmt ok' , function ( ) {
115
+ file . init ( ) ;
116
+ const data = file . fmt ( '${id}' , { id : 123 } ) ;
117
+ assert . equal ( data , '123' ) ;
118
+ } ) ;
101
119
} ) ; // #meta
120
+
121
+ describe ( '#genneral' , function ( ) {
122
+ beforeEach ( function ( ) {
123
+ th . clean ( ) ;
124
+ } ) ;
125
+ afterEach ( function ( ) {
126
+ th . clean ( ) ;
127
+ } ) ;
128
+
129
+ it ( 'should mkdir ok' , function ( ) {
130
+ const dir = th . DIR + 'dir' ;
131
+ assert . equal ( fs . existsSync ( dir ) , false ) ;
132
+ file . mkdir ( dir ) ;
133
+ assert . equal ( fs . existsSync ( dir ) , true ) ;
134
+ file . mkdir ( dir ) ;
135
+ assert . equal ( fs . existsSync ( dir ) , true ) ;
136
+ } ) ;
137
+
138
+ it ( 'should mv ok' , function ( ) {
139
+ const SRC = th . Dir + 'src' ;
140
+ const DST = th . DIR + 'dst' ;
141
+ assert . equal ( fs . existsSync ( SRC ) , false ) ;
142
+ assert . equal ( fs . existsSync ( DST ) , false ) ;
143
+ file . mkdir ( SRC ) ;
144
+ assert . equal ( fs . existsSync ( SRC ) , true ) ;
145
+ assert . equal ( fs . existsSync ( DST ) , false ) ;
146
+ file . mv ( SRC , DST ) ;
147
+ assert . equal ( fs . existsSync ( SRC ) , false ) ;
148
+ assert . equal ( fs . existsSync ( DST ) , true ) ;
149
+ } ) ;
150
+ } ) ; // #general
102
151
} ) ;
0 commit comments