A function `f` whose body is a `depth`-deep parenthesized expression.
(language: Language, depth: number)
| 65 | |
| 66 | /** A function `f` whose body is a `depth`-deep parenthesized expression. */ |
| 67 | function deepParens(language: Language, depth: number): string { |
| 68 | const open = '('.repeat(depth); |
| 69 | const close = ')'.repeat(depth); |
| 70 | switch (language) { |
| 71 | case 'typescript': case 'tsx': case 'javascript': case 'jsx': |
| 72 | return `function f() { return ${open}1${close}; }\n`; |
| 73 | case 'java': |
| 74 | return `class A {\n int f() { return ${open}1${close}; }\n}\n`; |
| 75 | case 'python': |
| 76 | return `def f():\n return ${open}1${close}\n`; |
| 77 | case 'go': |
| 78 | return `package p\n\nfunc f() int { return ${open}1${close} }\n`; |
| 79 | case 'c': |
| 80 | return `int f(void) { return ${open}1${close}; }\n`; |
| 81 | case 'cpp': |
| 82 | return `int f() { return ${open}1${close}; }\n`; |
| 83 | case 'rust': |
| 84 | return `fn f() -> i32 { ${open}1${close} }\n`; |
| 85 | case 'csharp': |
| 86 | return `class A {\n int f() { return ${open}1${close}; }\n}\n`; |
| 87 | case 'ruby': |
| 88 | return `def f\n ${open}1${close}\nend\n`; |
| 89 | case 'php': |
| 90 | return `<?php\nfunction f() { return ${open}1${close}; }\n`; |
| 91 | case 'swift': |
| 92 | return `func f() -> Int { return ${open}1${close} }\n`; |
| 93 | case 'kotlin': |
| 94 | return `fun f(): Int { return ${open}1${close} }\n`; |
| 95 | case 'r': |
| 96 | return `f <- function() {\n ${open}1${close}\n}\n`; |
| 97 | case 'lua': case 'luau': |
| 98 | return `local function f()\n return ${open}1${close}\nend\n`; |
| 99 | case 'scala': |
| 100 | return `object A {\n def f(): Int = ${open}1${close}\n}\n`; |
| 101 | case 'dart': |
| 102 | return `int f() { return ${open}1${close}; }\n`; |
| 103 | default: |
| 104 | throw new Error(`no deep fixture for ${language}`); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** The reporter's repro: a C function body of `depth` nested blocks. */ |
| 109 | function deepBraces(depth: number): string { |
no outgoing calls
no test coverage detected