<commit_before>component extends="testbox.system.BaseSpec" {

	variables.supportedFunctions = structKeyList(getFunctionList());

	function run(testResults, testBox) {
		dataDir = ExpandPath("../data/en");
		files = directoryList(dataDir, false, "array");
		
		describe("Test Examples", function() {
			it("should match the expected result", function() {
				for (filePath in files) {
					var json = fileRead(filePath);
					var isItJson = isJSON(json);
					var fileName = getFileFromPath(filePath);
					if (isItJson && find("""code""",json) && !listFind("queryexecute.json,entityload.json", fileName)) {
						json = deserializeJSON(json);
						if (json.keyExists("examples") && isArray(json.examples) && arrayLen(json.examples)) {
							if (structKeyExists(server, "lucee") AND NOT structKeyExists(json.engines, "lucee")) {
								//skip this test because it does not run on lucee, ACF specific tag or function
								continue;
							}
							for (var e in json.examples) {

								if (e.keyExists("code") && e.keyExists("result") && Len(e.result)) {
									if (json.type == "function" && !listFindNoCase(variables.supportedFunctions, json.name)) {
										//skip because it is not supported by current engine
										continue;
									}
									if (!find("<cf", e.code) && !find(";", e.code) && !find("{", e.code)) {
										var actualResult = "";
										try {
											actualResult = evaluate(e.code);
										} catch(any ex) {
											actualResult = "EXCEPTION: #ex.message#";
										}
										
										//workaround bug: listRemoveDuplicates adds trailing comma in lucee
										//https://luceeserver.atlassian.net/browse/LDEV-387
										if (json.name == "listRemoveDuplicates" && server.keyExists("lucee")) {
											if (right(actualResult, 1) == ",") {
												e.result = e.result & ",";
											}
										}

										expect(actualResult).toBe(e.result, "#fileName# example result is:#e.result# but evaluated to:#actualResult#");
									}
								}
							} 
						}
					}
					
				}<commit_msg>Update Boolean testing of examples<commit_after>component extends="testbox.system.BaseSpec" {

	variables.supportedFunctions = structKeyList(getFunctionList());

	function run(testResults, testBox) {
		dataDir = ExpandPath("../data/en");
		files = directoryList(dataDir, false, "array");
		
		describe("Test Examples", function() {
			it("should match the expected result", function() {
				for (filePath in files) {
					var json = fileRead(filePath);
					var isItJson = isJSON(json);
					var fileName = getFileFromPath(filePath);
					if (isItJson && find("""code""",json) && !listFind("queryexecute.json,entityload.json", fileName)) {
						json = deserializeJSON(json);
						if (json.keyExists("examples") && isArray(json.examples) && arrayLen(json.examples)) {
							if (structKeyExists(server, "lucee") AND NOT structKeyExists(json.engines, "lucee")) {
								//skip this test because it does not run on lucee, ACF specific tag or function
								continue;
							}
							for (var e in json.examples) {

								if (e.keyExists("code") && e.keyExists("result") && Len(e.result)) {
									if (json.type == "function" && !listFindNoCase(variables.supportedFunctions, json.name)) {
										//skip because it is not supported by current engine
										continue;
									}
									if (!find("<cf", e.code) && !find(";", e.code) && !find("{", e.code)) {
										var actualResult = "";
										try {
											actualResult = evaluate(e.code);
										} catch(any ex) {
											actualResult = "EXCEPTION: #ex.message#";
										}
										
										//workaround bug: listRemoveDuplicates adds trailing comma in lucee
										//https://luceeserver.atlassian.net/browse/LDEV-387
										if (json.name == "listRemoveDuplicates" && server.keyExists("lucee")) {
											if (right(actualResult, 1) == ",") {
												e.result = e.result & ",";
											}
										}
										if (isBoolean(e.result)) {
											if (e.result == true) {
												expect(actualResult).toBeTrue("#fileName# example result is:#e.result# but evaluated to:#actualResult#");
											} else {
												expect(actualResult).toBeFalse("#fileName# example result is:#e.result# but evaluated to:#actualResult#");
											}
										} else {
											expect(actualResult).toBe(e.result, "#fileName# example result is:#e.result# but evaluated to:#actualResult#");	
										}
										
									}
								}
							} 
						}
					}
					
				}
{'fraction_non_alphanumeric': 0.14633068081343945, 'fraction_numerical': 0.0017683465959328027, 'mean_word_length': 2.4436834094368343, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2947918', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1330, 'n_words': 297}