Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/printer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,17 @@ function genericPrint(path, options, print) {
);
}

case "ExtSlice": {
return printListLike(
path,
options,
"",
path.map(print, "dims"),
trailingComma,
""
);
}

case "UnaryOp": {
// We don't use a line or escapedLine with Not because wrapping and
// indenting doesn't make sense with a 4-space indent, since the operand
Expand Down
70 changes: 70 additions & 0 deletions tests/python_slices/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`list.py 1`] = `
a[-1]
a[-2:]
a[:-2]
a[::-1]
a[1::-1]
a[:-3:-1]
a[-3::-1]
point_coords = coords[i, :]
main(sys.argv[1:])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a[-1]
a[-2:]
a[:-2]
a[::-1]
a[1::-1]
a[:-3:-1]
a[-3::-1]
point_coords = coords[i, :]
main(sys.argv[1:])

`;

exports[`list.py 2`] = `
a[-1]
a[-2:]
a[:-2]
a[::-1]
a[1::-1]
a[:-3:-1]
a[-3::-1]
point_coords = coords[i, :]
main(sys.argv[1:])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a[-1]
a[-2:]
a[:-2]
a[::-1]
a[1::-1]
a[:-3:-1]
a[-3::-1]
point_coords = coords[i, :]
main(sys.argv[1:])

`;

exports[`list.py 3`] = `
a[-1]
a[-2:]
a[:-2]
a[::-1]
a[1::-1]
a[:-3:-1]
a[-3::-1]
point_coords = coords[i, :]
main(sys.argv[1:])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a[-1]
a[-2:]
a[:-2]
a[::-1]
a[1::-1]
a[:-3:-1]
a[-3::-1]
point_coords = coords[i, :]
main(sys.argv[1:])

`;
3 changes: 3 additions & 0 deletions tests/python_slices/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" });
run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" });
run_spec(__dirname, ["python"], { pythonVersion: "3" });
9 changes: 9 additions & 0 deletions tests/python_slices/list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a[-1]
a[-2:]
a[:-2]
a[::-1]
a[1::-1]
a[:-3:-1]
a[-3::-1]
point_coords = coords[i, :]
main(sys.argv[1:])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to see some tests involving wrapping. In particular, I'd like to see where that trailing comma gets placed.