• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / js-slang / 15237418122

25 May 2025 11:31AM UTC coverage: 77.048% (-3.5%) from 80.538%
15237418122

push

github

web-flow
Rewrite: Stepper (#1742)

3433 of 4826 branches covered (71.14%)

Branch coverage included in aggregate %.

1032 of 1260 new or added lines in 27 files covered. (81.9%)

440 existing lines in 29 files now uncovered.

10099 of 12737 relevant lines covered (79.29%)

142411.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.01
/src/repl/utils.ts
1
import { Option } from '@commander-js/extra-typings'
4✔
2

3
import { pyLanguages, scmLanguages, sourceLanguages } from '../constants'
4✔
4
import { Chapter, type Language, Variant, type Result, type LanguageOptions } from '../types'
4✔
5
import { stringify } from '../utils/stringify'
4✔
6
import Closure from '../cse-machine/closure'
4✔
7
import { parseError, type Context } from '..'
4✔
8
import { objectKeys } from '../utils/misc'
4✔
9

10
export function chapterParser(str: string): Chapter {
4✔
11
  let foundChapter: string | undefined
12

13
  if (/^-?[0-9]+$/.test(str)) {
10✔
14
    // Chapter is fully numeric
15
    const value = parseInt(str)
5✔
16
    foundChapter = objectKeys(Chapter).find(chapterName => Chapter[chapterName] === value)
70✔
17

18
    if (foundChapter === undefined) {
5✔
19
      throw new Error(`Invalid chapter value: ${str}`)
1✔
20
    }
21
  } else {
22
    foundChapter = str
5✔
23
  }
24

25
  if (foundChapter in Chapter) {
9✔
26
    return Chapter[foundChapter]
8✔
27
  }
28
  throw new Error(`Invalid chapter value: ${str}`)
1✔
29
}
30

31
export const getChapterOption = <T extends Chapter>(
4✔
32
  defaultValue: T,
33
  argParser: (value: string) => T
34
) => {
35
  return new Option('--chapter <chapter>').default(defaultValue).argParser(argParser)
28✔
36
}
37

38
export const getVariantOption = <T extends Variant>(defaultValue: T, choices: T[]) => {
4✔
39
  return new Option('--variant <variant>').default(defaultValue).choices(choices)
17✔
40
}
41

42
export const getLanguageOption = <T extends LanguageOptions>() => {
4✔
43
  return new Option('--languageOptions <options>')
17✔
44
    .default({})
45
    .argParser((value: string): LanguageOptions => {
46
      const languageOptions = value.split(',').map(lang => {
×
47
        const [key, value] = lang.split('=')
×
UNCOV
48
        return { [key]: value }
×
49
      })
UNCOV
50
      return Object.assign({}, ...languageOptions)
×
51
    })
52
}
53

54
export function validateChapterAndVariantCombo(language: Language) {
4✔
55
  for (const { chapter, variant } of sourceLanguages) {
5✔
56
    if (language.chapter === chapter && language.variant === variant) return true
40✔
57
  }
UNCOV
58
  return false
×
59
}
60

61
/**
62
 * Returns true iff the given chapter and variant combination is supported.
63
 */
64
export function validChapterVariant(language: Language) {
4✔
65
  const { chapter, variant } = language
10✔
66

67
  for (const lang of sourceLanguages) {
10✔
68
    if (lang.chapter === chapter && lang.variant === variant) return true
80✔
69
  }
70
  for (const lang of scmLanguages) {
×
UNCOV
71
    if (lang.chapter === chapter && lang.variant === variant) return true
×
72
  }
73
  for (const lang of pyLanguages) {
×
UNCOV
74
    if (lang.chapter === chapter && lang.variant === variant) return true
×
75
  }
76

UNCOV
77
  return false
×
78
}
79

80
export function handleResult(result: Result, context: Context, verboseErrors: boolean) {
4✔
81
  if (result.status === 'finished') {
28✔
82
    if (result.representation !== undefined) {
23!
UNCOV
83
      return result.representation
×
84
    }
85

86
    if (result.value instanceof Closure || typeof result.value === 'function') {
23!
UNCOV
87
      return result.value.toString()
×
88
    }
89

90
    return stringify(result.value)
23✔
91
  }
92

93
  return `Error: ${parseError(context.errors, verboseErrors)}`
5✔
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc