<commit_before>/*
 * testaddress.js - test the address parsing and formatting routines
 * 
 * Copyright © 2013, JEDLSoft
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// TODO: get some Luxembourg addresses

function testParseAddressNormal() {
	var parsedAddress = new ilib.Address("X", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("Achterberglaan 23", parsedAddress.streetAddress);
	assertEquals("Uithoorn", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("2345 GD", parsedAddress.postalCode);
	assertEquals("Nederland", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressNoZip() {
	var parsedAddress = new ilib.Address("X", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("Achterberglaan 23", parsedAddress.streetAddress);
	assertEquals("Uithoorn", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("Nederland", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
	assertUndefined(parsedAddress.postalCode);
};

function testParseAddressManyLines() {
	var parsedAddress = new ilib.Address("X", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("<NAME> 34, <NAME> 4, <NAME>, 15th Floor", parsedAddress.streetAddress);
	assertEquals("Amsterdam", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("1082 MD", parsedAddress.postalCode);
	assertEquals("Nederland", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressOneLine() {
	var parsedAddress = new ilib.Address("X", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("Startbaan 16", parsedAddress.streetAddress);
	assertEquals("Amstelveen", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("1187 XR", parsedAddress.postalCode);
	assertEquals("Nederland", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressSuperfluousWhitespace() {
	var parsedAddress = new ilib.Address("X", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("Startbaan 16", parsedAddress.streetAddress);
	assertEquals("Amstelveen", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("1187 XR", parsedAddress.postalCode);
	assertEquals("Nederland", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressNoDelimiters() {
	var parsedAddress = new ilib.Address("X", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("Startbaan 16", parsedAddress.streetAddress);
	assertEquals("Amstelveen", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("1187 XR", parsedAddress.postalCode);
	assertEquals("Nederland", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressSpecialChars() {
	var parsedAddress = new ilib.Address("X", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("Óók 16", parsedAddress.streetAddress);
	assertEquals("s'Hertogen-bósch", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("1187 XR", parsedAddress.postalCode);
	assertEquals("Nederland", parsedAddress.country);
	assertEquals("NL", parsedAddress.countryCode);
};

function testParseAddressFromUS() {
	var parsedAddress = new ilib.Address("X", {locale: 'en-US'});
	
	// the country name is in English because this address is for a contact in a US database
	
	assertNotUndefined(parsedAddress);
	assertEquals("Achterberglaan 23", parsedAddress.streetAddress);
	assertEquals("Uithoorn", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("2345 GD", parsedAddress.postalCode);
	assertEquals("The Netherlands", parsedAddress.country);
	assertEquals("NL", parsedAddress.countryCode);
};

function testFormatAddress() {
	var parsedAddress = new ilib.Address({
		streetAddress: "Achterberglaan 23",
		locality: "Uithoorn",
		postalCode: "2345 GD",
		country: "Nederland",
		countryCode: "NL"
	}, {locale: 'fr-LU'});
	
	var expected = "Achterberglaan 23\n2345 GD Uithoorn\nNederland";
	var formatter = new ilib.AddressFmt({locale: 'fr-LU'});
	assertEquals(expected, formatter.format(parsedAddress));
};

function testFormatAddressFromUS() {
	var parsedAddress = new ilib.Address({
		streetAddress: "Achterberglaan 23",
		locality: "Uithoorn",
		postalCode: "2345 GD",
		country: "Netherlands",
		countryCode: "NL"
	}, {locale: 'en-US'});
	
	var expected = "Achterberglaan 23\n2345 GD Uithoorn\nNetherlands";
	var formatter = new ilib.AddressFmt({locale: 'en-US'});
	assertEquals(expected, formatter.format(parsedAddress));
};<commit_msg>test cases<commit_after>/*
 * testaddress.js - test the address parsing and formatting routines
 * 
 * Copyright © 2013, JEDLSoft
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// TODO: get some Luxembourg addresses

function testParseAddressNormal() {
	var parsedAddress = new ilib.Address("M. Andrée TROMMER BP 501\nL-1050 Luxembourg\nLUXEMBOURG", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("M. Andrée TROMMER BP 501", parsedAddress.streetAddress);
	assertEquals("Luxembourg", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("L-1050", parsedAddress.postalCode);
	assertEquals("LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};


function testParseAddressotherNormal() {
	var parsedAddress = new ilib.Address("M. <NAME> 71, route de Longwy\nL-4750 PETANGE\nLUXEMBOURG", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("M. <NAME> 71, route de Longwy", parsedAddress.streetAddress);
	assertEquals("PETANGE", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("L-4750", parsedAddress.postalCode);
	assertEquals("GRAND DUCHY OF LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};


function testParseAddressNoZip() {
	var parsedAddress = new ilib.Address("M. Andrée TROMMER BP 5019\nLuxembourg\nLUXEMBOURG", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("M. Andrée TROMMER BP 5019", parsedAddress.streetAddress);
	assertEquals("Luxembourg", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
	assertUndefined(parsedAddress.postalCode);
};

function testParseAddressManyLines() {
	var parsedAddress = new ilib.Address("<NAME> 71\nroute\nde\nLongwy\nL-4750\nPETANGE\nLUXEMBOURG\n\n\n", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("<NAME> 71, route, de, Longwy", parsedAddress.streetAddress);
	assertEquals("PETANGE", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("L-4750", parsedAddress.postalCode);
	assertEquals("GRAND DUCHY OF LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressOneLine() {
	var parsedAddress = new ilib.Address("M. <NAME> 71, route, de, Longwy, L-4750, PETANGE, LUXEMBOURG", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("<NAME> 71, route, de, Longwy", parsedAddress.streetAddress);
	assertEquals("PETANGE", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("L-4750", parsedAddress.postalCode);
	assertEquals("GRAND DUCHY OF LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressSuperfluousWhitespace() {
	var parsedAddress = new ilib.Address("<NAME> 71\n\troute\n\tde\tLongwy\t\nL-4750\n\tPETANGE\n\tLUXEMBOURG\n\t", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("<NAME> 71, route, de, Longwy", parsedAddress.streetAddress);
	assertEquals("PETANGE", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("L-4750", parsedAddress.postalCode);
	assertEquals("GRAND DUCHY OF LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testParseAddressNoDelimiters() {
	var parsedAddress = new ilib.Address("M. Andrée TROMMER BP 5019 L-1050 Luxembourg LUXEMBOURG", {locale: 'fr-LU'});
	
	assertNotUndefined(parsedAddress);
	assertEquals("M. Andrée TROMMER BP 5019", parsedAddress.streetAddress);
	assertEquals("Luxembourg", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("L-1050", parsedAddress.postalCode);
	assertEquals("LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};


function testParseAddressFromUS() {
	var parsedAddress = new ilib.Address("M. Andrée TROMMER BP 501\nLuxembourg L-1050\nLUXEMBOURG", {locale: 'en-US'});
	
	// the country name is in English because this address is for a contact in a US database
	
	assertNotUndefined(parsedAddress);
	assertEquals("M. Andrée TROMMER BP 501", parsedAddress.streetAddress);
	assertEquals("Luxembourg", parsedAddress.locality);
	assertUndefined(parsedAddress.region);
	assertEquals("L-1050", parsedAddress.postalCode);
	assertEquals("LUXEMBOURG", parsedAddress.country);
	assertEquals("LU", parsedAddress.countryCode);
};

function testFormatAddress() {
	var parsedAddress = new ilib.Address({
		streetAddress: "M. Andrée TROMMER BP 5019",
		locality: "Luxembourg",
		postalCode: "L-1050",
		country: "LUXEMBOURG",
		countryCode: "LU"
	}, {locale: 'fr-LU'});
	
	var expected = "M. Andrée TROMMER BP 5019\nL-1050 Luxembourg\nLUXEMBOURG";
	var formatter = new ilib.AddressFmt({locale: 'fr-LU'});
	assertEquals(expected, formatter.format(parsedAddress));
};

function testFormatAddressFromUS() {
	var parsedAddress = new ilib.Address({
		streetAddress: "M. Andrée TROMMER BP 5019",
		locality: "Luxembourg",
		postalCode: "L-1050",
		country: "LUXEMBOURG",
		countryCode: "LU"
	}, {locale: 'en-US'});
	
	var expected = "M. Andrée TROMMER BP 5019\nLuxembourg L-1050\nLUXEMBOURG";
	var formatter = new ilib.AddressFmt({locale: 'en-US'});
	assertEquals(expected, formatter.format(parsedAddress));
};
{'fraction_non_alphanumeric': 0.1284182305630027, 'fraction_numerical': 0.019571045576407507, 'mean_word_length': 6.654582763337893, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2619700', 'n_tokens_mistral': 3731, 'n_tokens_neox': 3448, 'n_words': 788}