@@ -2,7 +2,7 @@ import { strict as assert } from "assert"
22
33import { Sitemap } from "../sitemap"
44
5- import { selectedVersionCorrespondingURL } from "./correspondingPage"
5+ import { selectedVersionCorrespondingURL , shortestCommonPrefix , stripPrefix } from "./correspondingPage"
66
77describe ( "Version switcher tests" , ( ) => {
88 // These examples are obtained by pausing the JS debugger in various situation and
@@ -54,7 +54,7 @@ describe("Version switcher tests", () => {
5454 "https://test.github.io/project/latest/foo/"
5555 ]
5656
57- it ( "does not (yet, TODO #7226) return a URL when the selected version has the current page" , ( ) => {
57+ it ( "returns a URL when the selected version has the current page" , ( ) => {
5858 assert . equal (
5959 selectedVersionCorrespondingURL ( {
6060 selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLatestVersion ) ,
@@ -64,7 +64,7 @@ describe("Version switcher tests", () => {
6464 currentLocation : new URL ( "https://test.github.io/project/0.2/bar/#heading?param=some" ) ,
6565 currentBaseURL : "https://test.github.io/project/0.2/"
6666 } ) ?. href ,
67- undefined ,
67+ "https://test.github.io/project/0.1/bar/#heading?param=some" ,
6868 )
6969 } )
7070 it ( "returns nothing when the selected version does not have the current page" , ( ) => {
@@ -92,15 +92,15 @@ describe("Version switcher tests", () => {
9292 "https://localhost/project/0.1/foo/"
9393 ]
9494
95- it ( "does not (yet, TODO) return a URL when the selected version has the current page" , ( ) => {
95+ it ( "returns a URL when the selected version has the current page" , ( ) => {
9696 assert . equal (
9797 selectedVersionCorrespondingURL ( {
9898 selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLocalhost ) ,
9999 selectedVersionBaseURL : new URL ( "https://localhost:8000/0.1/" ) ,
100100 currentLocation : new URL ( "https://localhost:8000/0.2/bar/#heading?param=some" ) ,
101101 currentBaseURL : "https://localhost:8000/0.2/"
102102 } ) ?. href ,
103- undefined ,
103+ "https://localhost:8000/0.1/bar/#heading?param=some" ,
104104 )
105105 } )
106106 it ( "returns nothing when the selected version does not have the current page" , ( ) => {
@@ -130,3 +130,16 @@ describe("Version switcher tests", () => {
130130function sitemapFromURLList ( urls : string [ ] ) : Sitemap {
131131 return new Map ( urls . map ( url => [ url , [ new URL ( url ) ] ] ) )
132132}
133+
134+ describe ( "Utility string processing function tests" , ( ) => {
135+ it ( "shortestCommonPrefix" , ( ) => {
136+ assert . equal ( shortestCommonPrefix ( [ ] ) , "" )
137+ assert . equal ( shortestCommonPrefix ( [ "abc" , "abcd" , "abe" ] ) , "ab" )
138+ assert . equal ( shortestCommonPrefix ( [ "abcef" , "abcd" , "abc" ] ) , "abc" )
139+ assert . equal ( shortestCommonPrefix ( [ "" , "abc" ] ) , "" )
140+ } )
141+ it ( "stripPrefix" , ( ) => {
142+ assert . equal ( stripPrefix ( "abc" , "ab" ) , "c" )
143+ assert . equal ( stripPrefix ( "abc" , "b" ) , undefined )
144+ } )
145+ } )
0 commit comments