Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf5f882c

Browse files
committed
parser test progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent740c1cf commitf5f882c

File tree

2 files changed

+121
-91
lines changed

2 files changed

+121
-91
lines changed

‎src/utils/parse.ts

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ export function parseMdContent(md: string): TutorialFrame | never {
9494

9595
typeParseParams={
9696
text:string;
97-
config:T.Tutorial;
97+
config:Partial<T.Tutorial|any>;
9898
commits:CommitLogObject;
9999
};
100100

101-
exportfunctionparse(params:ParseParams):T.Tutorial{
101+
exportfunctionparse(params:ParseParams):any{
102102
constparsed={ ...params.config};
103103

104104
constmdContent:TutorialFrame=parseMdContent(params.text);
@@ -110,71 +110,53 @@ export function parse(params: ParseParams): T.Tutorial {
110110
if(parsed.levels){
111111
parsed.levels.forEach((level:T.Level,levelIndex:number)=>{
112112
constlevelContent=mdContent[level.id];
113+
console.log(levelContent);
113114
if(!levelContent){
114115
console.log(`Markdown content not found for${level.id}`);
115116
return;
116117
}
117-
const{ steps, ...content}=levelContent;
118118

119-
if(steps){
120-
steps.forEach((step:T.Step,stepIndex:number)=>{
121-
return_.merge(step,steps[step.id]);
119+
// add level setup commits
120+
constlevelSetupKey=`L${levelIndex+1}S`;
121+
if(params.commits[levelSetupKey]){
122+
if(!level.setup){
123+
level.setup={
124+
commits:[],
125+
};
126+
}
127+
level.setup.commits=params.commits[levelSetupKey];
128+
}
129+
130+
// add level step commits
131+
if(levelContent.steps){
132+
levelContent.steps.forEach((step:T.Step,stepIndex:number)=>{
133+
conststepSetupKey=`${levelSetupKey}S${stepIndex+`1`}Q`;
134+
if(params.commits[stepSetupKey]){
135+
if(!step.setup){
136+
step.setup={
137+
commits:[],
138+
};
139+
}
140+
step.setup.commits=params.commits[stepSetupKey];
141+
}
142+
143+
conststepSolutionKey=`${levelSetupKey}S${stepIndex+`1`}A`;
144+
if(params.commits[stepSolutionKey]){
145+
if(!step.solution){
146+
step.solution={
147+
commits:[],
148+
};
149+
}
150+
step.solution.commits=params.commits[stepSolutionKey];
151+
}
152+
153+
return_.merge(step,levelContent.steps[step.id]);
122154
});
123155
}
124156

125-
_.merge(level,content);
157+
_.merge(level);
126158
});
127159
}
128160

129161
returnparsed;
130162
}
131-
132-
/*
133-
// Add the content and git hash to the tutorial
134-
if (matches.groups.stepId) {
135-
// If it's a step: add the content and the setup/solution hashes depending on the type
136-
const level: T.Level | null =
137-
tutorial.levels.find(
138-
(level: T.Level) => level.id === matches.groups.levelId
139-
) || null;
140-
if (!level) {
141-
console.log(`Level ${matches.groups.levelId} not found`);
142-
} else {
143-
const theStep: T.Step | null =
144-
level.steps.find(
145-
(step: T.Step) => step.id === matches.groups.stepId
146-
) || null;
147-
148-
if (!theStep) {
149-
console.log(`Step ${matches.groups.stepId} not found`);
150-
} else {
151-
if (matches.groups.stepType === "Q") {
152-
theStep.setup.commits.push(commit.hash.substr(0, 7));
153-
} else if (
154-
matches.groups.stepType === "A" &&
155-
theStep.solution &&
156-
theStep.solution.commits
157-
) {
158-
theStep.solution.commits.push(commit.hash.substr(0, 7));
159-
}
160-
}
161-
}
162-
} else {
163-
// If it's level: add the commit hash (if the level has the commit key) and the content to the tutorial
164-
const theLevel: T.Level | null =
165-
tutorial.levels.find(
166-
(level: T.Level) => level.id === matches.groups.levelId
167-
) || null;
168-
169-
if (!theLevel) {
170-
console.log(`Level ${matches.groups.levelId} not found`);
171-
} else {
172-
if (_.has(theLevel, "tutorial.commits")) {
173-
if (theLevel.setup) {
174-
theLevel.setup.commits.push(commit.hash.substr(0, 7));
175-
}
176-
}
177-
}
178-
}
179-
}
180-
*/

‎tests/parse.test.ts

Lines changed: 82 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ describe("parse", () => {
88
99
`;
1010

11-
constyaml=`version: "0.1.0"`;
12-
constresult=parse(md,yaml);
11+
constconfig={version:"0.1.0"};
12+
constresult=parse({
13+
text:md,
14+
config,
15+
commits:{},
16+
});
1317
constexpected={
1418
summary:{
1519
description:"Short description to be shown as a tutorial's subtitle.",
@@ -31,11 +35,15 @@ Description.
3135
Some text
3236
`;
3337

34-
constyaml=`version: "0.1.0"
35-
levels:
36-
- id: L1
37-
`;
38-
constresult=parse(md,yaml);
38+
constconfig={
39+
levels:[{id:"L1"}],
40+
};
41+
42+
constresult=parse({
43+
text:md,
44+
config,
45+
commits:{},
46+
});
3947
constexpected={
4048
levels:[
4149
{
@@ -62,17 +70,20 @@ Description.
6270
Some text
6371
`;
6472

65-
constyaml=`version: "0.1.0"
66-
levels:
67-
- id: L1
68-
setup:
69-
files: []
70-
commits: []
71-
solution:
72-
files: []
73-
commits: []
74-
`;
75-
constresult=parse(md,yaml);
73+
constconfig={
74+
levels:[
75+
{
76+
id:"L1",
77+
setup:{files:[],commits:[]},
78+
solution:{files:[],commits:[]},
79+
},
80+
],
81+
};
82+
constresult=parse({
83+
text:md,
84+
config,
85+
commits:{},
86+
});
7687
constexpected={
7788
levels:[
7889
{
@@ -99,11 +110,12 @@ Description.
99110
Some text that becomes the summary
100111
`;
101112

102-
constyaml=`version: "0.1.0"
103-
levels:
104-
- id: L1
105-
`;
106-
constresult=parse(md,yaml);
113+
constconfig={levels:[{id:1}]};
114+
constresult=parse({
115+
text:md,
116+
config,
117+
commits:{},
118+
});
107119
constexpected={
108120
levels:[
109121
{
@@ -127,11 +139,12 @@ Description.
127139
Some text that becomes the summary and goes beyond the maximum length of 80 so that it gets truncated at the end
128140
`;
129141

130-
constyaml=`version: "0.1.0"
131-
levels:
132-
- id: L1
133-
`;
134-
constresult=parse(md,yaml);
142+
constconfig={levels:[{id:"L1"}]};
143+
constresult=parse({
144+
text:md,
145+
config,
146+
commits:{},
147+
});
135148
constexpected={
136149
levels:[
137150
{
@@ -161,11 +174,12 @@ Second line
161174
Third line
162175
`;
163176

164-
constyaml=`version: "0.1.0"
165-
levels:
166-
- id: L1
167-
`;
168-
constresult=parse(md,yaml);
177+
constconfig={levels:[{id:"L1"}]};
178+
constresult=parse({
179+
text:md,
180+
config,
181+
commits:{},
182+
});
169183
constexpected={
170184
summary:{
171185
description:"Description.\n\nSecond description line",
@@ -208,7 +222,41 @@ config:
208222
- name: node
209223
version: '>=10'
210224
`;
211-
constresult=parse(md,yaml);
225+
226+
constconfig={
227+
config:{
228+
testRunner:{
229+
command:"./node_modules/.bin/mocha",
230+
args:{
231+
filter:"--grep",
232+
tap:"--reporter=mocha-tap-reporter",
233+
},
234+
directory:"coderoad",
235+
setup:{
236+
commits:["abcdefg1"],
237+
commands:[],
238+
},
239+
},
240+
appVersions:{
241+
vscode:">=0.7.0",
242+
},
243+
repo:{
244+
uri:"https://path.to/repo",
245+
branch:"aBranch",
246+
},
247+
dependencies:[
248+
{
249+
name:"node",
250+
version:">=10",
251+
},
252+
],
253+
},
254+
};
255+
constresult=parse({
256+
text:md,
257+
config,
258+
commits:{},
259+
});
212260
constexpected={
213261
summary:{
214262
description:"Description.\n\nSecond description line",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp