HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/librepanel/node_modules/uri-templates/test/test.js
"use strict";

var uriTemplates = require('../uri-templates');
var assert = require('proclaim');

describe("Basic tests", function () {

	it("Basic substitution", function () {
		var template = uriTemplates("/prefix/{var}/suffix");
		var uri = template.fillFromObject({var: "test"});

		assert.strictEqual(uri, "/prefix/test/suffix");
	});
});

function createTests(title, examplesDoc) {
	describe(title + "(substitution)", function () {
		for (var sectionTitle in examplesDoc) {
			var exampleSet = examplesDoc[sectionTitle];
			describe(sectionTitle, function () {
				var variables = exampleSet.variables;
				var variableFunction = function (varName) {
					return variables[varName];
				};

				for (var i = 0; i < exampleSet.testcases.length; i++) {
					var pair = exampleSet.testcases[i];

					(function (templateString, expected) {
						it(templateString, function () {
							var template = uriTemplates(templateString);
							var actualUri = template.fillFromObject(variables);
							if (typeof expected == "string") {
								assert.strictEqual(actualUri, expected);
							} else {
								assert.includes(expected, actualUri);
							}

							[].concat(expected).forEach(function (expected) {
								var isMatch = template.test(expected);
								assert.strictEqual(isMatch, true);
							});
						});
					})(pair[0], pair[1]);
				}
			});
		}
	});

	var unguessable = {};

	describe(title + " (de-substitution)", function () {
		for (var sectionTitle in examplesDoc) {
			var exampleSet = examplesDoc[sectionTitle];
			describe(sectionTitle, function () {
				for (var i = 0; i < exampleSet.testcases.length; i++) {
					var pair = exampleSet.testcases[i];

					(function (templateString, expected, exampleSet) {
						if (unguessable[templateString]) {
							return;
						}

						it(templateString, function () {
							[].concat(expected).forEach(function (original) {
								var template = uriTemplates(templateString);

								var guessedVariables = template.fromUri(original);
								assert.isObject(guessedVariables, 'guess is object');
								var reconstructed = template.fillFromObject(guessedVariables);
								if (typeof expected == "string") {
									assert.strictEqual(reconstructed, expected, 'reconstruction matches');
								} else {
									assert.includes(expected, reconstructed, 'reconstruction matches');
								}

								var guessedVariablesStrict = template.fromUri(original, {strict: true});
								assert.isObject(guessedVariablesStrict, 'strict guess is object');
								var reconstructedStrict = template.fillFromObject(guessedVariablesStrict);
								if (typeof expected == "string") {
									assert.strictEqual(reconstructedStrict, expected, 'strict reconstruction matches');
								} else {
									assert.includes(expected, reconstructedStrict, 'strict reconstruction matches');
								}
							});
						});
					})(pair[0], pair[1], exampleSet);
				}
			});
		}
	});
}

createTests("Spec examples by section", require('./uritemplate-test/spec-examples-by-section.json'));
createTests("Extended examples", require('./uritemplate-test/extended-tests.json'));

createTests("Custom examples 1", require('./custom-tests.json'));
createTests("Custom examples 2", require('./custom-tests-2.json'));

require('./custom-tests.js');