Update URL tests
This commit is contained in:
parent
73a31c090c
commit
6a91404a27
@ -70,9 +70,9 @@ export const parseUrl = (url: URL): LiveAtlasParsedUrl | null => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the given hash into a {@link LiveAtlasParsedUrl}, if the hash matches the LiveAtlas URL hash format
|
* Parses the given hash into a {@link LiveAtlasParsedUrl}, if the hash matches the LiveAtlas or Overviewer URL hash format
|
||||||
* @param {string} hash The hash to parse
|
* @param {string} hash The hash to parse
|
||||||
* @returns {LiveAtlasParsedUrl | null} A LiveAtlasParsedUrl if the provided hash matched the LiveAtlas URL
|
* @returns {LiveAtlasParsedUrl | null} A LiveAtlasParsedUrl if the provided hash matched the LiveAtlas or Overviewer URL
|
||||||
* hash format, otherwise null
|
* hash format, otherwise null
|
||||||
*/
|
*/
|
||||||
export const parseMapHash = (hash: string): LiveAtlasParsedUrl | null => {
|
export const parseMapHash = (hash: string): LiveAtlasParsedUrl | null => {
|
||||||
|
@ -20,7 +20,7 @@ import {LiveAtlasParsedUrl} from "@/index";
|
|||||||
const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
||||||
[
|
[
|
||||||
'Dynmap - complete',
|
'Dynmap - complete',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4&x=6885&y=64&z=24608'),
|
new URL('https://example.com/build?worldname=world&mapname=surface&zoom=4&x=6885&y=64&z=24608'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -31,7 +31,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - no location',
|
'Dynmap - no location',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&zoom=4'),
|
new URL('https://example.com/build?worldname=world&mapname=surface&zoom=4'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -42,7 +42,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - no zoom',
|
'Dynmap - no zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface&x=6885&y=64&z=24608'),
|
new URL('https://example.com/build?worldname=world&mapname=surface&x=6885&y=64&z=24608'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -53,7 +53,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - no zoom or location',
|
'Dynmap - no zoom or location',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?worldname=world&mapname=surface'),
|
new URL('https://example.com/build?worldname=world&mapname=surface'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -64,7 +64,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - no map, zoom or location',
|
'Dynmap - no map, zoom or location',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?worldname=world'),
|
new URL('https://example.com/build?worldname=world'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: undefined,
|
map: undefined,
|
||||||
@ -75,7 +75,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Pl3xmap - complete',
|
'Pl3xmap - complete',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4&x=6885&y=64&z=24608'),
|
new URL('https://example.com/build?world=world&zoom=4&x=6885&z=24608'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: undefined,
|
map: undefined,
|
||||||
@ -86,7 +86,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Pl3xmap - no location',
|
'Pl3xmap - no location',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?world=world&zoom=4'),
|
new URL('https://example.com/build?world=world&zoom=4'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: undefined,
|
map: undefined,
|
||||||
@ -97,7 +97,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Pl3xmap - no zoom',
|
'Pl3xmap - no zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?world=world&x=6885&y=64&z=24608'),
|
new URL('https://example.com/build?world=world&x=6885&z=24608'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: undefined,
|
map: undefined,
|
||||||
@ -108,7 +108,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Pl3xmap - no zoom or location',
|
'Pl3xmap - no zoom or location',
|
||||||
new URL('https://minecraft.rtgame.co.uk/build?world=world'),
|
new URL('https://example.com/build?world=world'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: undefined,
|
map: undefined,
|
||||||
@ -117,9 +117,20 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
legacy: true
|
legacy: true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'Overviewer - complete',
|
||||||
|
new URL('https://example.com/#/-269/64/244/-3/world/map'),
|
||||||
|
{
|
||||||
|
world: 'world',
|
||||||
|
map: 'map',
|
||||||
|
location: {x: -269, y: 64, z:244},
|
||||||
|
zoom: undefined,
|
||||||
|
legacy: false
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - complete',
|
'LiveAtlas - complete',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;2'),
|
new URL('https://example.com/map/survival#world;flat;168,64,1914;2'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -130,7 +141,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - no zoom',
|
'LiveAtlas - no zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914'),
|
new URL('https://example.com/map/survival#world;flat;168,64,1914'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -141,7 +152,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - no location or zoom',
|
'LiveAtlas - no location or zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat'),
|
new URL('https://example.com/map/survival#world;flat'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -152,7 +163,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - no map, location or zoom',
|
'LiveAtlas - no map, location or zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world'),
|
new URL('https://example.com/map/survival#world'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: undefined,
|
map: undefined,
|
||||||
@ -166,7 +177,7 @@ const validURLs: [string, URL, LiveAtlasParsedUrl][] = [
|
|||||||
const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
||||||
[
|
[
|
||||||
'LiveAtlas - negative zoom',
|
'LiveAtlas - negative zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;-2'),
|
new URL('https://example.com/map/survival#world;flat;168,64,1914;-2'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -177,7 +188,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - NaN zoom',
|
'LiveAtlas - NaN zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,1914;ewsjtuiewshfoes'),
|
new URL('https://example.com/map/survival#world;flat;168,64,1914;ewsjtuiewshfoes'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -188,7 +199,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - missing z coordinate',
|
'LiveAtlas - missing z coordinate',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64;2'),
|
new URL('https://example.com/map/survival#world;flat;168,64;2'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -199,7 +210,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - NaN z coordinate',
|
'LiveAtlas - NaN z coordinate',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168,64,j;2'),
|
new URL('https://example.com/map/survival#world;flat;168,64,j;2'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -210,7 +221,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - missing y and z coordinates',
|
'LiveAtlas - missing y and z coordinates',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;168;2'),
|
new URL('https://example.com/map/survival#world;flat;168;2'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -221,7 +232,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'LiveAtlas - invalid location',
|
'LiveAtlas - invalid location',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#world;flat;23wteyuisezujsezr'),
|
new URL('https://example.com/map/survival#world;flat;23wteyuisezujsezr'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'flat',
|
map: 'flat',
|
||||||
@ -232,7 +243,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - Negative zoom',
|
'Dynmap - Negative zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=-2&x=6885&y=64&z=24608'),
|
new URL('https://example.com/map/survival?worldname=world&mapname=surface&zoom=-2&x=6885&y=64&z=24608'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -243,7 +254,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - NaN zoom',
|
'Dynmap - NaN zoom',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=fsghrtdrh&x=6885&y=64&z=24608'),
|
new URL('https://example.com/map/survival?worldname=world&mapname=surface&zoom=fsghrtdrh&x=6885&y=64&z=24608'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -254,7 +265,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - Missing z coordinate',
|
'Dynmap - Missing z coordinate',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64'),
|
new URL('https://example.com/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -265,7 +276,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - NaN z coordinate',
|
'Dynmap - NaN z coordinate',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64&z=j'),
|
new URL('https://example.com/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&y=64&z=j'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -276,7 +287,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - Missing y and z coordinates',
|
'Dynmap - Missing y and z coordinates',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&zoom=2&x=6885'),
|
new URL('https://example.com/map/survival?worldname=world&mapname=surface&zoom=2&x=6885'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -287,7 +298,7 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - Invalid/missing coordinates',
|
'Dynmap - Invalid/missing coordinates',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?worldname=world&mapname=surface&x=3wresfsg'),
|
new URL('https://example.com/map/survival?worldname=world&mapname=surface&x=3wresfsg'),
|
||||||
{
|
{
|
||||||
world: 'world',
|
world: 'world',
|
||||||
map: 'surface',
|
map: 'surface',
|
||||||
@ -298,17 +309,77 @@ const invalidURLs: [string, URL, LiveAtlasParsedUrl|null][] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Dynmap - Missing world',
|
'Dynmap - Missing world',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?mapname=surface&x=3wresfsg'),
|
new URL('https://example.com/map/survival?mapname=surface&x=3wresfsg'),
|
||||||
null
|
null
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'Pl3xmap - Negative zoom',
|
||||||
|
new URL('https://example.com/map/survival?world=world&zoom=-2&x=6885&z=24608'),
|
||||||
|
{
|
||||||
|
world: 'world',
|
||||||
|
map: undefined,
|
||||||
|
location: {x: 6885, y: 64, z: 24608},
|
||||||
|
zoom: undefined,
|
||||||
|
legacy: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Pl3xmap - NaN zoom',
|
||||||
|
new URL('https://example.com/map/survival?world=world&zoom=fsghrtdrh&x=6885&z=24608'),
|
||||||
|
{
|
||||||
|
world: 'world',
|
||||||
|
map: undefined,
|
||||||
|
location: {x: 6885, y: 64, z: 24608},
|
||||||
|
zoom: undefined,
|
||||||
|
legacy: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Pl3xmap - Missing z coordinate',
|
||||||
|
new URL('https://example.com/map/survival?world=world&zoom=2&x=6885'),
|
||||||
|
{
|
||||||
|
world: 'world',
|
||||||
|
map: undefined,
|
||||||
|
location: undefined,
|
||||||
|
zoom: 2,
|
||||||
|
legacy: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Pl3xmap - NaN z coordinate',
|
||||||
|
new URL('https://example.com/map/survival?worldname=world&mapname=surface&zoom=2&x=6885&z=j'),
|
||||||
|
{
|
||||||
|
world: 'world',
|
||||||
|
map: 'surface',
|
||||||
|
location: undefined,
|
||||||
|
zoom: 2,
|
||||||
|
legacy: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Pl3xmap - Invalid/missing coordinates',
|
||||||
|
new URL('https://example.com/map/survival?world=world&x=3wresfsg'),
|
||||||
|
{
|
||||||
|
world: 'world',
|
||||||
|
map: undefined,
|
||||||
|
location: undefined,
|
||||||
|
zoom: undefined,
|
||||||
|
legacy: true
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'empty hash',
|
'empty hash',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival#'),
|
new URL('https://example.com/map/survival#'),
|
||||||
null
|
null
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'empty query',
|
'empty query',
|
||||||
new URL('https://minecraft.rtgame.co.uk/map/survival?'),
|
new URL('https://example.com/map/survival?'),
|
||||||
|
null
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'invalid query',
|
||||||
|
new URL('https://example.com/map/survival?invalid=aaa&bbb=54'),
|
||||||
null
|
null
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user