JS: add Util::pluralize, also add tests for Util::capitalize

This commit is contained in:
Esben Sparre Andreasen
2018-10-11 13:44:38 +02:00
parent 3af91d5d0a
commit c65bc5cc90
6 changed files with 22 additions and 0 deletions

View File

@@ -11,3 +11,16 @@ bindingset[s]
string capitalize(string s) {
result = s.charAt(0).toUpperCase() + s.suffix(1)
}
/**
* Gets the pluralization for `n` occurrences of `noun`.
*
* For example, the pluralization of `"function"` for `n = 2` is `"functions"`.
*/
bindingset[noun, n]
string pluralize(string noun, int n) {
if n = 1 then
result = noun
else
result = noun + "s"
}

View File

@@ -0,0 +1 @@
| X | X | Xx | XX | Xx | XX |

View File

@@ -0,0 +1,3 @@
import semmle.javascript.Util
select capitalize("x"), capitalize("X"), capitalize("xx"), capitalize("XX"), capitalize("Xx"), capitalize("xX")

View File

@@ -0,0 +1 @@
| xs | x | xs | xs |

View File

@@ -0,0 +1,3 @@
import semmle.javascript.Util
select pluralize("x", 0), pluralize("x", 1), pluralize("x", 2), pluralize("x", -1)

View File

@@ -0,0 +1 @@
// used by qltest to identify the language