diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b19e34b7..43045324e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. For change log formatting, see http://keepachangelog.com/ -# Unreleased +## Unreleased - Better u-turn instructions - Fix rotary names instruction `exit onto` - Only mention end-of-road on uturn intructions +- Respect name and ref for way_name ## 0.0.2 2016-10-18 diff --git a/index.js b/index.js index 3b8231eed..0b2a93019 100644 --- a/index.js +++ b/index.js @@ -111,12 +111,24 @@ module.exports = function(_version) { // NOOP, since no special logic for that type } + // Decide way_name with special handling for name and ref + var wayName; + var name = (step.name || '').replace(new RegExp(' (' + step.ref + ')$'), ''); // Remove hack from Mapbox Directions mixing ref into name + var ref = (step.ref || '').split(';')[0]; + if (name && ref && name !== ref) { + wayName = name + ' (' + ref + ')'; + } else if (!name && ref) { + wayName = ref; + } else { + wayName = name; + } + // Decide which instruction string to use // Destination takes precedence over name var instruction; if (step.destinations && instructionObject.destination) { instruction = instructionObject.destination; - } else if (step.name && instructionObject.name) { + } else if (wayName && instructionObject.name) { instruction = instructionObject.name; } else { instruction = instructionObject.default; @@ -126,14 +138,14 @@ module.exports = function(_version) { // NOOP if they don't exist var nthWaypoint = ''; // TODO, add correct waypoint counting instruction = instruction - .replace('{nth}', nthWaypoint) + .replace('{way_name}', wayName) .replace('{destination}', (step.destinations || '').split(',')[0]) .replace('{exit_number}', this.ordinalize(step.maneuver.exit || 1)) .replace('{rotary_name}', step.rotary_name) .replace('{lane_instruction}', laneInstruction) .replace('{modifier}', instructions[version].constants.modifier[modifier]) .replace('{direction}', this.directionFromDegree(step.maneuver.bearing_after)) - .replace('{way_name}', step.name) + .replace('{nth}', nthWaypoint) .replace(/ {2}/g, ' '); // remove excess spaces return instruction; diff --git a/scripts/generate_fixtures.js b/scripts/generate_fixtures.js index 8d97a9405..93a39d493 100644 --- a/scripts/generate_fixtures.js +++ b/scripts/generate_fixtures.js @@ -5,14 +5,19 @@ var path = require('path'); var instructions = require('../index.js'); var v5Instructions = instructions('v5'); +var constants = require('../test/constants'); var type = process.argv[2]; function clone(obj) { return JSON.parse(JSON.stringify(obj)); } +function underscorify(input) { + return input.replace(/ /g, '_'); +} + function write(step, p) { - fs.writeFileSync(p, JSON.stringify(step, null, 4)); + fs.writeFileSync(p, JSON.stringify(step, null, 4) + '\n'); } function writeVariations(basePath, baseStep, onlyDefault) { @@ -50,6 +55,51 @@ function writeVariations(basePath, baseStep, onlyDefault) { function execute() { switch (type) { + case 'turn': + var basePath = path.join(__dirname, '..', 'test', 'fixtures', 'v5', 'turn'); + + // do name_ref combinations + var baseStep = { + maneuver: { + type: 'turn', + modifier: 'left' + }, + name: '', + ref: 'Ref1;Ref2' + }; + writeVariations(path.join(basePath, 'left_ref'), baseStep, true); + baseStep = { + maneuver: { + type: 'turn', + modifier: 'left' + }, + name: 'Way Name', + ref: 'Ref1;Ref2' + }; + writeVariations(path.join(basePath, 'left_ref_name'), baseStep, true); + baseStep = { + maneuver: { + type: 'turn', + modifier: 'left' + }, + name: 'Way Name', + ref: 'Ref1;Ref2', + destinations: 'Destination 1,Destination 2' + }; + writeVariations(path.join(basePath, 'left_destination_ref_name'), baseStep, true); + + // do variation per modifier + constants.modifiers.forEach((modifier) => { + baseStep = { + maneuver: { + type: 'turn', + modifier: modifier + }, + name: '' + }; + writeVariations(path.join(basePath, underscorify(modifier)), baseStep); + }); + break; case 'rotary': // default var basePath = path.join(__dirname, '..', 'test', 'fixtures', 'v5', 'rotary', 'default'); diff --git a/test/fixtures/v5/turn/left_no_name.json b/test/fixtures/v5/turn/left_default.json similarity index 100% rename from test/fixtures/v5/turn/left_no_name.json rename to test/fixtures/v5/turn/left_default.json diff --git a/test/fixtures/v5/turn/left_destination.json b/test/fixtures/v5/turn/left_destination.json new file mode 100644 index 000000000..2c55f9b09 --- /dev/null +++ b/test/fixtures/v5/turn/left_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "left" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Turn left towards Destination 1" +} diff --git a/test/fixtures/v5/turn/left_destination_ref_name_default.json b/test/fixtures/v5/turn/left_destination_ref_name_default.json new file mode 100644 index 000000000..06147e9c1 --- /dev/null +++ b/test/fixtures/v5/turn/left_destination_ref_name_default.json @@ -0,0 +1,12 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "left" + }, + "name": "Way Name", + "ref": "Ref1;Ref2", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Turn left towards Destination 1" +} diff --git a/test/fixtures/v5/turn/left.json b/test/fixtures/v5/turn/left_name.json similarity index 60% rename from test/fixtures/v5/turn/left.json rename to test/fixtures/v5/turn/left_name.json index 7a94c22f6..10a59b1fa 100644 --- a/test/fixtures/v5/turn/left.json +++ b/test/fixtures/v5/turn/left_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "left" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Turn left onto Street Name" + "instruction": "Turn left onto Way Name" } diff --git a/test/fixtures/v5/turn/left_ref_default.json b/test/fixtures/v5/turn/left_ref_default.json new file mode 100644 index 000000000..3e4a0d166 --- /dev/null +++ b/test/fixtures/v5/turn/left_ref_default.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "left" + }, + "name": "", + "ref": "Ref1;Ref2" + }, + "instruction": "Turn left onto Ref1" +} diff --git a/test/fixtures/v5/turn/left_ref_name_default.json b/test/fixtures/v5/turn/left_ref_name_default.json new file mode 100644 index 000000000..9bf25dae1 --- /dev/null +++ b/test/fixtures/v5/turn/left_ref_name_default.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "left" + }, + "name": "Way Name", + "ref": "Ref1;Ref2" + }, + "instruction": "Turn left onto Way Name (Ref1)" +} diff --git a/test/fixtures/v5/turn/right_no_name.json b/test/fixtures/v5/turn/right_default.json similarity index 100% rename from test/fixtures/v5/turn/right_no_name.json rename to test/fixtures/v5/turn/right_default.json diff --git a/test/fixtures/v5/turn/right_destination.json b/test/fixtures/v5/turn/right_destination.json new file mode 100644 index 000000000..bd0ccab40 --- /dev/null +++ b/test/fixtures/v5/turn/right_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "right" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Turn right towards Destination 1" +} diff --git a/test/fixtures/v5/turn/right.json b/test/fixtures/v5/turn/right_name.json similarity index 59% rename from test/fixtures/v5/turn/right.json rename to test/fixtures/v5/turn/right_name.json index 950dc5eea..44fd07ee1 100644 --- a/test/fixtures/v5/turn/right.json +++ b/test/fixtures/v5/turn/right_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "right" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Turn right onto Street Name" + "instruction": "Turn right onto Way Name" } diff --git a/test/fixtures/v5/turn/sharp_left_no_name.json b/test/fixtures/v5/turn/sharp_left_default.json similarity index 100% rename from test/fixtures/v5/turn/sharp_left_no_name.json rename to test/fixtures/v5/turn/sharp_left_default.json diff --git a/test/fixtures/v5/turn/sharp_left_destination.json b/test/fixtures/v5/turn/sharp_left_destination.json new file mode 100644 index 000000000..2cf985f1e --- /dev/null +++ b/test/fixtures/v5/turn/sharp_left_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "sharp left" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Make a sharp left towards Destination 1" +} diff --git a/test/fixtures/v5/turn/sharp_left.json b/test/fixtures/v5/turn/sharp_left_name.json similarity index 58% rename from test/fixtures/v5/turn/sharp_left.json rename to test/fixtures/v5/turn/sharp_left_name.json index 7f72066e4..729f9a393 100644 --- a/test/fixtures/v5/turn/sharp_left.json +++ b/test/fixtures/v5/turn/sharp_left_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "sharp left" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Make a sharp left onto Street Name" + "instruction": "Make a sharp left onto Way Name" } diff --git a/test/fixtures/v5/turn/sharp_right_no_name.json b/test/fixtures/v5/turn/sharp_right_default.json similarity index 100% rename from test/fixtures/v5/turn/sharp_right_no_name.json rename to test/fixtures/v5/turn/sharp_right_default.json diff --git a/test/fixtures/v5/turn/sharp_right_destination.json b/test/fixtures/v5/turn/sharp_right_destination.json new file mode 100644 index 000000000..729a733db --- /dev/null +++ b/test/fixtures/v5/turn/sharp_right_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "sharp right" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Make a sharp right towards Destination 1" +} diff --git a/test/fixtures/v5/turn/sharp_right.json b/test/fixtures/v5/turn/sharp_right_name.json similarity index 58% rename from test/fixtures/v5/turn/sharp_right.json rename to test/fixtures/v5/turn/sharp_right_name.json index b6158206f..d32741bc9 100644 --- a/test/fixtures/v5/turn/sharp_right.json +++ b/test/fixtures/v5/turn/sharp_right_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "sharp right" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Make a sharp right onto Street Name" + "instruction": "Make a sharp right onto Way Name" } diff --git a/test/fixtures/v5/turn/slight_left_no_name.json b/test/fixtures/v5/turn/slight_left_default.json similarity index 100% rename from test/fixtures/v5/turn/slight_left_no_name.json rename to test/fixtures/v5/turn/slight_left_default.json diff --git a/test/fixtures/v5/turn/slight_left_destination.json b/test/fixtures/v5/turn/slight_left_destination.json new file mode 100644 index 000000000..1aa35a564 --- /dev/null +++ b/test/fixtures/v5/turn/slight_left_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "slight left" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Make a slight left towards Destination 1" +} diff --git a/test/fixtures/v5/turn/slight_left.json b/test/fixtures/v5/turn/slight_left_name.json similarity index 58% rename from test/fixtures/v5/turn/slight_left.json rename to test/fixtures/v5/turn/slight_left_name.json index 5d250e6f8..184b6131d 100644 --- a/test/fixtures/v5/turn/slight_left.json +++ b/test/fixtures/v5/turn/slight_left_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "slight left" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Make a slight left onto Street Name" + "instruction": "Make a slight left onto Way Name" } diff --git a/test/fixtures/v5/turn/slight_right_no_name.json b/test/fixtures/v5/turn/slight_right_default.json similarity index 100% rename from test/fixtures/v5/turn/slight_right_no_name.json rename to test/fixtures/v5/turn/slight_right_default.json diff --git a/test/fixtures/v5/turn/slight_right_destination.json b/test/fixtures/v5/turn/slight_right_destination.json new file mode 100644 index 000000000..6fb6fb3a2 --- /dev/null +++ b/test/fixtures/v5/turn/slight_right_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "slight right" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Make a slight right towards Destination 1" +} diff --git a/test/fixtures/v5/turn/slight_right.json b/test/fixtures/v5/turn/slight_right_name.json similarity index 58% rename from test/fixtures/v5/turn/slight_right.json rename to test/fixtures/v5/turn/slight_right_name.json index 6960b25af..bcbed1f22 100644 --- a/test/fixtures/v5/turn/slight_right.json +++ b/test/fixtures/v5/turn/slight_right_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "slight right" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Make a slight right onto Street Name" + "instruction": "Make a slight right onto Way Name" } diff --git a/test/fixtures/v5/turn/straight_no_name.json b/test/fixtures/v5/turn/straight_default.json similarity index 100% rename from test/fixtures/v5/turn/straight_no_name.json rename to test/fixtures/v5/turn/straight_default.json diff --git a/test/fixtures/v5/turn/straight_destination.json b/test/fixtures/v5/turn/straight_destination.json new file mode 100644 index 000000000..71ad87b52 --- /dev/null +++ b/test/fixtures/v5/turn/straight_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "straight" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Go straight towards Destination 1" +} diff --git a/test/fixtures/v5/turn/straight.json b/test/fixtures/v5/turn/straight_name.json similarity index 60% rename from test/fixtures/v5/turn/straight.json rename to test/fixtures/v5/turn/straight_name.json index f867f7d6b..20fd78c22 100644 --- a/test/fixtures/v5/turn/straight.json +++ b/test/fixtures/v5/turn/straight_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "straight" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Go straight onto Street Name" + "instruction": "Go straight onto Way Name" } diff --git a/test/fixtures/v5/turn/uturn_no_name.json b/test/fixtures/v5/turn/uturn_default.json similarity index 100% rename from test/fixtures/v5/turn/uturn_no_name.json rename to test/fixtures/v5/turn/uturn_default.json diff --git a/test/fixtures/v5/turn/uturn_destination.json b/test/fixtures/v5/turn/uturn_destination.json new file mode 100644 index 000000000..8b50c5c83 --- /dev/null +++ b/test/fixtures/v5/turn/uturn_destination.json @@ -0,0 +1,11 @@ +{ + "step": { + "maneuver": { + "type": "turn", + "modifier": "uturn" + }, + "name": "Way Name", + "destinations": "Destination 1,Destination 2" + }, + "instruction": "Make a U-turn towards Destination 1" +} diff --git a/test/fixtures/v5/turn/uturn.json b/test/fixtures/v5/turn/uturn_name.json similarity index 59% rename from test/fixtures/v5/turn/uturn.json rename to test/fixtures/v5/turn/uturn_name.json index 6ba3c5a20..3a3420ebb 100644 --- a/test/fixtures/v5/turn/uturn.json +++ b/test/fixtures/v5/turn/uturn_name.json @@ -4,7 +4,7 @@ "type": "turn", "modifier": "uturn" }, - "name": "Street Name" + "name": "Way Name" }, - "instruction": "Make a U-turn onto Street Name" + "instruction": "Make a U-turn onto Way Name" } diff --git a/test/index_test.js b/test/index_test.js index befe6825a..666976c24 100644 --- a/test/index_test.js +++ b/test/index_test.js @@ -99,6 +99,21 @@ tape.test('v5 compile', function(t) { } function checkModifiers(type) { + constants.modifiers.forEach(function(modifier) { + assert.ok( + fs.existsSync(path.join(basePath, underscorify(type), `${underscorify(modifier)}_default.json`)), + `${type}/${modifier}_default`); + assert.ok( + fs.existsSync(path.join(basePath, underscorify(type), `${underscorify(modifier)}_destination.json`)), + `${type}/${modifier}_destination`); + assert.ok( + fs.existsSync(path.join(basePath, underscorify(type), `${underscorify(modifier)}_name.json`)), + `${type}/${modifier}_name`); + }); + } + + function checkModifiersNoName(type) { + // TODO: Remove this function and replace it complately by checkModifiers constants.modifiers.forEach(function(modifier) { // check normal fixture var p = path.join(basePath, underscorify(type), underscorify(modifier) + '.json'); @@ -118,6 +133,22 @@ tape.test('v5 compile', function(t) { constants.types.forEach(function(type) { switch(type) { + case 'turn': + // name_ref combinations + assert.ok( + fs.existsSync(path.join(basePath, 'turn', `left_ref_default.json`)), + `${type}/left_ref_default`); + assert.ok( + fs.existsSync(path.join(basePath, 'turn', `left_ref_default.json`)), + `${type}/left_ref_name`); + assert.ok( + fs.existsSync(path.join(basePath, 'turn', `left_ref_default.json`)), + `${type}/left_destination_ref_name`); + + // regular combinations + checkModifiers(type); + + break; case 'rotary': [ 'default', 'exit_1', 'name', 'name_exit' ].forEach((s) => { assert.ok( @@ -152,7 +183,7 @@ tape.test('v5 compile', function(t) { }); break; default: - checkModifiers(type); + checkModifiersNoName(type); break }; });