@@ -10,20 +10,27 @@ import { namedFilesDesc, oneChange } from "../../generate/message";
1010
1111describe ( "Generate commit message for a single changed file" , function ( ) {
1212 // Notes:
13- // - The command `git status --short` expects XY format but this is for `git
14- // diff-index` which is only X . Also there is just spaces between - no
15- // '->' symbol.
13+ // - The command `git status --short` expects `XY` format but this is for
14+ // `git diff-index` which is only `X` . Also there is just spaces between -
15+ // no '->' symbol.
1616 // - Impossible cases are not covered here, like renaming a file and the
1717 // name and path are unchanged, or including two file names for an add
1818 // line. But validation on at least file name is done.
1919 describe ( "#oneChange" , function ( ) {
2020 it ( "returns the appropriate commit message for a new file" , function ( ) {
2121 assert . strictEqual ( oneChange ( "A\tfoo.txt" ) , "create foo.txt" ) ;
22- // Maybe create foo.txt in bar, if the dir is not too long?
22+
23+ // TODO: Maybe 'create foo.txt in bar', if the dir is not too long?
2324 assert . strictEqual ( oneChange ( "A\tbar/foo.txt" ) , "create foo.txt" ) ;
25+
26+ assert . strictEqual ( oneChange ( "A\tfoo bar.txt" ) , "create 'foo bar.txt'" ) ;
27+ assert . strictEqual (
28+ oneChange ( "A\tfizz buzz/foo bar.txt" ) ,
29+ "create 'foo bar.txt'"
30+ ) ;
2431 } ) ;
2532
26- it ( "throws an error if no filepath can be no generated" , function ( ) {
33+ it ( "throws an error if no file path can be no generated" , function ( ) {
2734 assert . throws ( ( ) => oneChange ( "A " ) ) ;
2835 } ) ;
2936
@@ -58,7 +65,7 @@ describe("Generate commit message for a single changed file", function () {
5865 ) ;
5966 } ) ;
6067
61- it ( "describes a file moved out of the repo root" , function ( ) {
68+ it ( "describes a file moved out of the repo root to another directory " , function ( ) {
6269 assert . strictEqual (
6370 oneChange ( "R\tfoo.txt\tfizz/foo.txt" ) ,
6471 "move foo.txt to fizz"
@@ -68,6 +75,16 @@ describe("Generate commit message for a single changed file", function () {
6875 oneChange ( "R\tfoo.txt\tfizz/buzz/foo.txt" ) ,
6976 "move foo.txt to fizz/buzz"
7077 ) ;
78+
79+ assert . strictEqual (
80+ oneChange ( "R\tfoo.txt\tfizz buzz/foo.txt" ) ,
81+ "move foo.txt to 'fizz buzz'"
82+ ) ;
83+
84+ assert . strictEqual (
85+ oneChange ( "R\tfoo bar.txt\tfizz/foo bar.txt" ) ,
86+ "move 'foo bar.txt' to fizz"
87+ ) ;
7188 } ) ;
7289
7390 it ( "describes a file moved out of a subdirectory" , function ( ) {
@@ -82,9 +99,14 @@ describe("Generate commit message for a single changed file", function () {
8299 ) ;
83100
84101 assert . strictEqual (
85- oneChange ( "R\tfizz/buzz/ foo.txt\tfizz/buzz/foo.txt" ) ,
102+ oneChange ( "R\tfizz/foo.txt\tfizz/buzz/foo.txt" ) ,
86103 "move foo.txt to fizz/buzz"
87104 ) ;
105+
106+ assert . strictEqual (
107+ oneChange ( "R\tfizz/foo bar.txt\tfizz/buzz baz/foo bar.txt" ) ,
108+ "move 'foo bar.txt' to 'fizz/buzz baz'"
109+ ) ;
88110 } ) ;
89111
90112 it ( "describes a file that was both moved and renamed" , function ( ) {
@@ -102,6 +124,11 @@ describe("Generate commit message for a single changed file", function () {
102124 oneChange ( "R\tbar/foo.txt\tfizz/fuzz.txt" ) ,
103125 "move and rename foo.txt to fizz/fuzz.txt"
104126 ) ;
127+
128+ assert . strictEqual (
129+ oneChange ( "R\tbar/foo.txt\tfizz/baz fuzz.txt" ) ,
130+ "move and rename foo.txt to 'fizz/baz fuzz.txt'"
131+ ) ;
105132 } ) ;
106133
107134 it ( "ignores percentage changed value for a file that was both moved and renamed" , function ( ) {
@@ -127,6 +154,10 @@ describe("Generate commit message for a single changed file", function () {
127154 ) ;
128155
129156 assert . strictEqual ( oneChange ( "A\tfoo/index.md" ) , "create foo/index.md" ) ;
157+ assert . strictEqual (
158+ oneChange ( "A\tfoo/index bazz.md" ) ,
159+ "create 'foo/index bazz.md'"
160+ ) ;
130161 assert . strictEqual ( oneChange ( "A\tfoo/index.js" ) , "create foo/index.js" ) ;
131162 } ) ;
132163 } ) ;
@@ -143,6 +174,14 @@ describe("Generate description for a few changed files which each get named", fu
143174 "create foo.txt and bar.txt"
144175 ) ;
145176
177+ assert . strictEqual (
178+ namedFilesDesc ( [
179+ { x : "A" , from : "foo bar.txt" , y : " " , to : "" } ,
180+ { x : "A" , from : "fizz buzz.txt" , y : " " , to : "" } ,
181+ ] ) ,
182+ "create 'foo bar.txt' and 'fizz buzz.txt'"
183+ ) ;
184+
146185 assert . strictEqual (
147186 namedFilesDesc ( [
148187 { x : "M" , from : "foo.txt" , y : " " , to : "" } ,
@@ -170,6 +209,15 @@ describe("Generate description for a few changed files which each get named", fu
170209 "create foo.txt, bar.txt and buzz.js"
171210 ) ;
172211
212+ assert . strictEqual (
213+ namedFilesDesc ( [
214+ { x : "A" , from : "foo.txt" , y : " " , to : "" } ,
215+ { x : "A" , from : "docs/bar fuzz.txt" , y : " " , to : "" } ,
216+ { x : "A" , from : "buzz.js" , y : " " , to : "" } ,
217+ ] ) ,
218+ "create foo.txt, 'bar fuzz.txt' and buzz.js"
219+ ) ;
220+
173221 assert . strictEqual (
174222 namedFilesDesc ( [
175223 { x : "D" , from : "foo.txt" , y : " " , to : "" } ,
0 commit comments