-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.cfm
41 lines (34 loc) · 1.23 KB
/
demo.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<cfset languageDetector = new languageDetector()>
<CFPARAM NAME="Form.Message" DEFAULT="">
<cfoutput>
<div style="padding:50px;">
<form id="form1" name="form1" method="post" action="#CGI.Script_Name#">
<textarea name="message" style="max-width:500px; width:98%; height:100px;" required placeholder="Enter text to be tested.">#Form.Message#</textarea><br>
<button type="submit">Perform Test</button>
</form>
</div>
</cfoutput>
<cfset testData = [
{
"Type" = "User-Defined",
"Text" = trim(Form.Message)
}
]>
<cfset useCustom = len(testData[1].Text)>
<cfif useCustom>
<cfoutput>
<p><a href="#CGI.Script_Name#">Return to unit tests</a></p>
</cfoutput>
<cfelse>
<cfset testData = deserializeJSON(fileRead(expandPath("./test.json"), "utf-8"))>
</cfif>
<cfoutput>
<cfloop from="1" to="#arrayLen(testData)#" index="i">
<cfset result = languageDetector.detect(testData[i].text)>
<cfset isCorrect = testData[i].Type IS Result OR useCustom>
<fieldset>
<legend style="background-color:<CFIF isCorrect>lightgreen<cfelse>lightpink</cfif>;"><b>#i#. #result#<cfif not isCorrect> <i>(expected #testData[i].Type#)</i></cfif></b></legend>
#testData[i].text#
</fieldset>
</cfloop>
</cfoutput>