Skip to content

Commit 3ea131b

Browse files
committed
AnchoredSpreadsheetSelection.urlFragment leading slash added
- inserted sample comment into AnchoredSpreadsheetSelection#urlFragment
1 parent 11b3dc4 commit 3ea131b

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

src/main/java/walkingkooka/spreadsheet/viewport/AnchoredSpreadsheetSelection.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,21 @@ public void printTree(final IndentingPrinter printer) {
106106

107107
// HasUrlFragment...................................................................................................
108108

109+
// /A1
110+
// /A2:B3/top-left
111+
109112
@Override
110113
public UrlFragment urlFragment() {
111114
final UrlFragment selection = this.selection()
112115
.urlFragment();
113116
final SpreadsheetViewportAnchor anchor = this.anchor();
114117

115-
return SpreadsheetViewportAnchor.NONE != anchor ?
116-
selection.append(UrlFragment.SLASH)
117-
.append(anchor.urlFragment()) :
118-
selection;
118+
return UrlFragment.SLASH.append(
119+
SpreadsheetViewportAnchor.NONE != anchor ?
120+
selection.append(UrlFragment.SLASH)
121+
.append(anchor.urlFragment()) :
122+
selection
123+
);
119124
}
120125

121126
// Object..........................................................................................................

src/test/java/walkingkooka/spreadsheet/viewport/AnchoredSpreadsheetSelectionTest.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121
import walkingkooka.HashCodeEqualsDefinedTesting2;
2222
import walkingkooka.ToStringTesting;
23-
import walkingkooka.net.UrlFragment;
23+
import walkingkooka.net.HasUrlFragmentTesting;
2424
import walkingkooka.reflect.ClassTesting;
2525
import walkingkooka.reflect.JavaVisibility;
2626
import walkingkooka.spreadsheet.reference.SpreadsheetSelection;
@@ -36,7 +36,8 @@ public final class AnchoredSpreadsheetSelectionTest implements ClassTesting<Anch
3636
HashCodeEqualsDefinedTesting2<AnchoredSpreadsheetSelection>,
3737
ToStringTesting<AnchoredSpreadsheetSelection>,
3838
JsonNodeMarshallingTesting<AnchoredSpreadsheetSelection>,
39-
TreePrintableTesting {
39+
TreePrintableTesting,
40+
HasUrlFragmentTesting {
4041

4142
private final static SpreadsheetSelection SELECTION = SpreadsheetSelection.parseCellRange("A1:B2");
4243
private final static SpreadsheetViewportAnchor ANCHOR = SpreadsheetViewportAnchor.BOTTOM_RIGHT;
@@ -202,21 +203,30 @@ public void testTreePrint() {
202203
}
203204

204205
// HasUrlFragment...................................................................................................
206+
205207
@Test
206-
public void testHasUrlFragmentCell() {
207-
this.checkEquals(
208-
UrlFragment.parse("A1"),
209-
SpreadsheetSelection.A1
210-
.urlFragment()
208+
public void testUrlFragmentCellWithCell() {
209+
this.urlFragmentAndCheck(
210+
SpreadsheetSelection.A1.setDefaultAnchor(),
211+
"/A1"
211212
);
212213
}
213214

214215
@Test
215-
public void testHasUrlFragmentCellRange() {
216-
this.checkEquals(
217-
UrlFragment.parse("A1:B2/bottom-right"),
218-
this.createObject()
219-
.urlFragment()
216+
public void testUrlFragmentCellWithCellRange() {
217+
this.urlFragmentAndCheck(
218+
SpreadsheetSelection.parseCellRange("B2:C3")
219+
.setAnchor(SpreadsheetViewportAnchor.TOP_LEFT),
220+
"/B2:C3/top-left"
221+
);
222+
}
223+
224+
@Test
225+
public void testUrlFragmentCellWithLabel() {
226+
this.urlFragmentAndCheck(
227+
SpreadsheetSelection.labelName("Label123")
228+
.setDefaultAnchor(),
229+
"/Label123"
220230
);
221231
}
222232

src/test/java/walkingkooka/spreadsheet/viewport/SpreadsheetViewportTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public void testTreePrintRectangleAnchoredSelectionRowRangeNavigations() {
427427
public void testUrlFragmentCell() {
428428
this.urlFragmentAndCheck(
429429
SpreadsheetSelection.A1.setDefaultAnchor(),
430-
"A1"
430+
"/A1"
431431
);
432432
}
433433

@@ -436,7 +436,7 @@ public void testUrlFragmentCellRangeTopLeft() {
436436
this.urlFragmentAndCheck(
437437
SpreadsheetSelection.parseCellRange("B2:C3")
438438
.setAnchor(SpreadsheetViewportAnchor.TOP_LEFT),
439-
"B2:C3/top-left"
439+
"/B2:C3/top-left"
440440
);
441441
}
442442

@@ -445,7 +445,7 @@ public void testUrlFragmentCellRangeTopRight() {
445445
this.urlFragmentAndCheck(
446446
SpreadsheetSelection.parseCellRange("B2:C3")
447447
.setAnchor(SpreadsheetViewportAnchor.TOP_RIGHT),
448-
"B2:C3/top-right"
448+
"/B2:C3/top-right"
449449
);
450450
}
451451

@@ -454,7 +454,7 @@ public void testUrlFragmentColumnNone() {
454454
this.urlFragmentAndCheck(
455455
SpreadsheetSelection.parseColumn("Z")
456456
.setDefaultAnchor(),
457-
"Z"
457+
"/Z"
458458
);
459459
}
460460

@@ -463,7 +463,7 @@ public void testUrlFragmentColumnRangeLeft() {
463463
this.urlFragmentAndCheck(
464464
SpreadsheetSelection.parseColumnRange("X:Y")
465465
.setAnchor(SpreadsheetViewportAnchor.LEFT),
466-
"X:Y/left"
466+
"/X:Y/left"
467467
);
468468
}
469469

@@ -472,7 +472,7 @@ public void testUrlFragmentColumnRangeRight() {
472472
this.urlFragmentAndCheck(
473473
SpreadsheetSelection.parseColumnRange("X:Y")
474474
.setAnchor(SpreadsheetViewportAnchor.RIGHT),
475-
"X:Y/right"
475+
"/X:Y/right"
476476
);
477477
}
478478

@@ -481,7 +481,7 @@ public void testUrlFragmentLabelNone() {
481481
this.urlFragmentAndCheck(
482482
SpreadsheetSelection.parseCellOrLabel("Label123")
483483
.setDefaultAnchor(),
484-
"Label123"
484+
"/Label123"
485485
);
486486
}
487487

@@ -490,7 +490,7 @@ public void testUrlFragmentLabelBottomRight() {
490490
this.urlFragmentAndCheck(
491491
SpreadsheetSelection.parseCellOrLabel("Label123")
492492
.setAnchor(SpreadsheetViewportAnchor.BOTTOM_RIGHT),
493-
"Label123/bottom-right"
493+
"/Label123/bottom-right"
494494
);
495495
}
496496

0 commit comments

Comments
 (0)