|
1 | 1 | import reducer from '../reducers';
|
2 | 2 | import { editCode } from '../reducers/code';
|
3 |
| - |
4 | 3 | import { hasMainFunctionSelector } from './index';
|
5 | 4 |
|
6 |
| -const buildState = (code: string) => { |
7 |
| - const state = reducer(undefined, editCode(code)); |
8 |
| - return state; |
9 |
| -}; |
| 5 | +const buildState = (code: string) => reducer(undefined, editCode(code)); |
| 6 | + |
| 7 | +const doMainFunctionSelector = (code: string) => hasMainFunctionSelector(buildState(code)); |
10 | 8 |
|
11 | 9 | describe('checking for a main function', () => {
|
12 | 10 | test('empty code has no main', () => {
|
13 |
| - expect(hasMainFunctionSelector(buildState(''))).toBe(false); |
| 11 | + expect(doMainFunctionSelector('')).toBe(false); |
14 | 12 | });
|
15 | 13 |
|
16 | 14 | test('a plain main counts', () => {
|
17 |
| - expect(hasMainFunctionSelector(buildState('fn main()'))).toBe(true); |
| 15 | + expect(doMainFunctionSelector('fn main()')).toBe(true); |
18 | 16 | });
|
19 | 17 |
|
20 | 18 | test('a public main counts', () => {
|
21 |
| - expect(hasMainFunctionSelector(buildState('pub fn main()'))).toBe(true); |
| 19 | + expect(doMainFunctionSelector('pub fn main()')).toBe(true); |
22 | 20 | });
|
23 | 21 |
|
24 | 22 | test('an async main counts', () => {
|
25 |
| - expect(hasMainFunctionSelector(buildState('async fn main()'))).toBe(true); |
| 23 | + expect(doMainFunctionSelector('async fn main()')).toBe(true); |
26 | 24 | });
|
27 | 25 |
|
28 | 26 | test('a public async main counts', () => {
|
29 |
| - expect(hasMainFunctionSelector(buildState('pub async fn main()'))).toBe(true); |
| 27 | + expect(doMainFunctionSelector('pub async fn main()')).toBe(true); |
30 | 28 | });
|
31 | 29 |
|
32 | 30 | test('a const main counts', () => {
|
33 |
| - expect(hasMainFunctionSelector(buildState('const fn main()'))).toBe(true); |
| 31 | + expect(doMainFunctionSelector('const fn main()')).toBe(true); |
34 | 32 | });
|
35 | 33 |
|
36 | 34 | test('a public const main counts', () => {
|
37 |
| - expect(hasMainFunctionSelector(buildState('pub const fn main()'))).toBe(true); |
| 35 | + expect(doMainFunctionSelector('pub const fn main()')).toBe(true); |
38 | 36 | });
|
39 | 37 |
|
40 | 38 | test('a public const async main counts', () => {
|
41 |
| - expect(hasMainFunctionSelector(buildState('pub const async fn main()'))).toBe(true); |
| 39 | + expect(doMainFunctionSelector('pub const async fn main()')).toBe(true); |
42 | 40 | });
|
43 | 41 |
|
44 | 42 | test('leading indentation is ignored', () => {
|
45 |
| - expect(hasMainFunctionSelector(buildState('\t fn main()'))).toBe(true); |
| 43 | + expect(doMainFunctionSelector('\t fn main()')).toBe(true); |
46 | 44 | });
|
47 | 45 |
|
48 | 46 | test('extra space everywhere is ignored', () => {
|
49 |
| - expect(hasMainFunctionSelector(buildState(' pub async fn main ( )'))).toBe(true); |
| 47 | + expect(doMainFunctionSelector(' pub async fn main ( )')).toBe(true); |
50 | 48 | });
|
51 | 49 |
|
52 | 50 | test('a commented-out main does not count', () => {
|
53 |
| - expect(hasMainFunctionSelector(buildState('// fn main()'))).toBe(false); |
54 |
| - expect(hasMainFunctionSelector(buildState('/* fn main()'))).toBe(false); |
| 51 | + expect(doMainFunctionSelector('// fn main()')).toBe(false); |
| 52 | + expect(doMainFunctionSelector('/* fn main()')).toBe(false); |
55 | 53 | });
|
56 | 54 |
|
57 | 55 | test('a function with the substring main does not count', () => {
|
58 |
| - expect(hasMainFunctionSelector(buildState('fn mainly()'))).toBe(false); |
| 56 | + expect(doMainFunctionSelector('fn mainly()')).toBe(false); |
| 57 | + }); |
| 58 | + |
| 59 | + test('a main function after other items on the same line', () => { |
| 60 | + expect(doMainFunctionSelector('use std; fn main(){ println!("Hello, world!"); }')).toBe(true); |
| 61 | + }); |
| 62 | + |
| 63 | + test('a main function with a block comment in the argument list', () => { |
| 64 | + expect(doMainFunctionSelector('fn main(/* comment */) {')).toBe(true); |
59 | 65 | });
|
60 | 66 | });
|
0 commit comments