Skip to content

Commit

Permalink
Improve problem name parser to handle numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
agrawal-d committed Feb 12, 2022
1 parent 5d523cc commit 26c60b7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
verbose: false,
silent: true,
};
3 changes: 2 additions & 1 deletion src/companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { saveProblem } from './parser';
import * as vscode from 'vscode';
import path from 'path';
import { writeFileSync, readFileSync, existsSync } from 'fs';
import { isCodeforcesUrl, randomId, words_in_text } from './utils';
import { isCodeforcesUrl, randomId } from './utils';
import {
getDefaultLangPref,
getLanguageId,
Expand All @@ -16,6 +16,7 @@ import {
import { getProblemName } from './submit';
import { spawn } from 'child_process';
import { getJudgeViewProvider } from './extension';
import { words_in_text } from './utilsPure';

const emptyResponse: CphEmptyResponse = { empty: true };
let savedResponse: CphEmptyResponse | CphSubmitResponse = emptyResponse;
Expand Down
21 changes: 21 additions & 0 deletions src/tests/utilsPure.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { words_in_text } from '../utilsPure';

describe('problem name parser', () => {
test('mix of latin, non latin and numbers', () => {
const output = ['apple', '12345', 'mango', 'India', 'こんにちは', '7'];
const input = 'apple 12345 mango India こんにちは 7';
expect(words_in_text(input)).toEqual(output);
});

test('just a number', () => {
const output = ['23'];
const input = '23';
expect(words_in_text(input)).toEqual(output);
});

test('just a word', () => {
const output = ['grapes'];
const input = 'grapes';
expect(words_in_text(input)).toEqual(output);
});
});
5 changes: 0 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,3 @@ export const getProblemForDocument = (
const problem: Problem = JSON.parse(readFileSync(probPath).toString());
return problem;
};

export const words_in_text = function (text: string) {
const regex = /[\p{L}-]+/gu;
return text.match(regex);
};
4 changes: 4 additions & 0 deletions src/utilsPure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const words_in_text = function (text: string) {
const regex = /[\p{L}-]+|[0-9]+/gu;
return text.match(regex);
};

0 comments on commit 26c60b7

Please sign in to comment.