Skip to content

Commit 6437562

Browse files
committed
TST: polish test script, remove beta_proportion_cdf
1 parent abc5976 commit 6437562

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

syntax/stan.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ syntax keyword stanFunction beta
151151
syntax keyword stanFunction beta_lpdf beta_cdf beta_lcdf beta_lccdf beta_rng
152152

153153
syntax keyword stanFunction beta_proportion
154-
syntax keyword stanFunction beta_proportion_lpdf beta_proportion_cdf beta_proportion_lcdf beta_proportion_lccdf beta_proportion_rng
154+
syntax keyword stanFunction beta_proportion_lpdf beta_proportion_lcdf beta_proportion_lccdf beta_proportion_rng
155155

156156
syntax keyword stanFunction von_mises
157157
syntax keyword stanFunction von_mises_lpdf von_mises_rng

tests/test_function_coverage.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import re
2+
from itertools import chain
23
import requests
34

4-
FUNCTION_SIGNATURES_FILE = "https://raw.githubusercontent.com/stan-dev/stan/develop/src/stan/lang/function_signatures.h"
5+
6+
# Path to stan-vim syntax file
57
SYNTAX_FILE = "syntax/stan.vim"
8+
9+
# Syntax declarations
10+
SYNTAX_HIGHLIGHTS = [
11+
"syntax keyword stanFunction",
12+
"syntax keyword stanConstant",
13+
"syntax keyword stanSpecial",
14+
]
15+
16+
# URL for Stan function signatures file
17+
FUNCTION_SIGNATURES_FILE = "https://raw.githubusercontent.com/stan-dev/stan/develop/src/stan/lang/function_signatures.h"
18+
19+
# Functions that Stan uses to register function signatures
620
STAN_ADD_FUNCTIONS = [
721
"add",
822
"add_unary",
@@ -20,29 +34,31 @@
2034
msg = "Could not request Stan file."
2135
raise RuntimeError(msg)
2236

23-
# Read syntax file
37+
# Read stan-vim syntax file
2438
with open(SYNTAX_FILE, "r") as f:
2539
syntax_file = f.read()
2640

27-
# Find all functions from Stan file
41+
# Find functions declarations from Stan file
2842
add_functions = "|".join(STAN_ADD_FUNCTIONS)
2943
regex = r"(?<=[{}]\(['\"])(\w+)(?=['\"])".format(add_functions)
30-
stan_functions = set(re.findall(regex, stan_file))
31-
# Remove _log functions
44+
matches = set(re.findall(regex, stan_file))
3245
stan_functions = {
33-
function for function in stan_functions if not function.endswith("_log")
46+
# Remove matches that end with "_log"
47+
match
48+
for match in matches
49+
if not match.endswith("_log")
3450
}
35-
# Add bare distribution names
3651
stan_functions = stan_functions | {
37-
function[:-4] for function in stan_functions if function.endswith("_rng")
52+
# Add bare distribution names
53+
function[:-4]
54+
for function in stan_functions
55+
if function.endswith("_rng")
3856
}
3957

40-
regex1 = r"(?<=syntax keyword stanFunction )(.*)"
41-
regex2 = r"(?<=syntax keyword stanConstant )(.*)"
42-
matches = re.findall(regex1, syntax_file) + re.findall(regex2, syntax_file)
43-
44-
# Flatten
45-
highlighted_functions = set([word for match in matches for word in match.split()])
58+
# Find highlighted words from stan-vim syntax file
59+
regexes = [r"(?<={} )(.*)".format(declaration) for declaration in SYNTAX_HIGHLIGHTS]
60+
matches = list(chain(*[re.findall(regex, syntax_file) for regex in regexes]))
61+
highlighted_functions = set(chain(*[match.split() for match in matches]))
4662

4763
missing = stan_functions - highlighted_functions
4864
unnecessary = highlighted_functions - stan_functions

0 commit comments

Comments
 (0)