Skip to content

Commit

Permalink
Rename function to match expectations. Flip all boolean logic
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Dec 13, 2024
1 parent bcb9a2d commit d624d26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/settings-view/lib/package-keymap-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class PackageKeymapView {
continue
}

if (this.selectorIsNotCompatibleWithPlatform(selector)) {
if (!this.selectorIsCompatibleWithPlatform(selector)) {
continue;
}

Expand Down Expand Up @@ -183,10 +183,10 @@ export default class PackageKeymapView {
atom.clipboard.write(content)
}

selectorIsNotCompatibleWithPlatform(selector, platform = process.platform) {
selectorIsCompatibleWithPlatform(selector, platform = process.platform) {
const otherPlatformPattern = new RegExp(`\\.platform-(?!${_.escapeRegExp(platform)}\\b)`);
const currentPlatformPattern = new RegExp(`\\.platform-(${_.escapeRegExp(platform)}\\b)`);

return otherPlatformPattern.test(selector) && !currentPlatformPattern.test(selector);
return !(otherPlatformPattern.test(selector) && !currentPlatformPattern.test(selector));
}
}
16 changes: 8 additions & 8 deletions packages/settings-view/spec/package-keymap-view-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ describe("PackageKeymapView", () => {
});

it("should say a selector with no platform listed is compatible with the current one", () => {
expect(view.selectorIsNotCompatibleWithPlatform("atom-text-editor", "win32")).toBe(false);
expect(view.selectorIsCompatibleWithPlatform("atom-text-editor", "win32")).toBe(true);
});

it("should say a selector with a platform other than the current is not compatible", () => {
expect(view.selectorIsNotCompatibleWithPlatform(".platform-darwin", "linux")).toBe(true);
expect(view.selectorIsNotCompatibleWithPlatform(".platform-win32", "darwin")).toBe(true);
expect(view.selectorIsCompatibleWithPlatform(".platform-darwin", "linux")).toBe(false);
expect(view.selectorIsCompatibleWithPlatform(".platform-win32", "darwin")).toBe(false);
});

it("should say a selector with the current platform listed is compatible", () => {
expect(view.selectorIsNotCompatibleWithPlatform(".platform-linux", "linux")).toBe(false);
expect(view.selectorIsNotCompatibleWithPlatform(".platform-win32", "win32")).toBe(false);
expect(view.selectorIsNotCompatibleWithPlatform(".platform-darwin", "darwin")).toBe(false);
expect(view.selectorIsCompatibleWithPlatform(".platform-linux", "linux")).toBe(true);
expect(view.selectorIsCompatibleWithPlatform(".platform-win32", "win32")).toBe(true);
expect(view.selectorIsCompatibleWithPlatform(".platform-darwin", "darwin")).toBe(true);
});

it("should say a selector with the current platform and others listed is compatible", () => {
expect(view.selectorIsNotCompatibleWithPlatform(".platform-linux, .platform-win32", "win32")).toBe(false);
expect(view.selectorIsNotCompatibleWithPlatform(".platform-linux, .platform-win32", "linux")).toBe(false);
expect(view.selectorIsCompatibleWithPlatform(".platform-linux, .platform-win32", "win32")).toBe(true);
expect(view.selectorIsCompatibleWithPlatform(".platform-linux, .platform-win32", "linux")).toBe(true);
});
});

0 comments on commit d624d26

Please sign in to comment.