       expect(grammars2.selectGrammar(filePath).name).toBe 'Ruby'
 
   describe ".selectGrammar(filePath)", ->
+    it "always returns a grammar", ->
+      registry = new GrammarRegistry()
+      expect(registry.selectGrammar().scopeName).toBe 'text.plain.null-grammar'
+
+    it "selects the text.plain grammar over the null grammar", ->
+      expect(atom.grammars.selectGrammar('test.txt').scopeName).toBe 'text.plain'
+
+    it "selects a grammar based on the file path case insensitively", ->
+      expect(atom.grammars.selectGrammar('/tmp/source.coffee').scopeName).toBe 'source.coffee'
+      expect(atom.grammars.selectGrammar('/tmp/source.COFFEE').scopeName).toBe 'source.coffee'
+
+    describe "on Windows", ->
+      originalPlatform = null
+
+      beforeEach ->
+        originalPlatform = process.platform
+        Object.defineProperty process, 'platform', value: 'win32'
+
+      afterEach ->
+        Object.defineProperty process, 'platform', value: originalPlatform
+
+      it "normalizes back slashes to forward slashes when matching the fileTypes", ->
+        expect(atom.grammars.selectGrammar('something\\.git\\config').scopeName).toBe 'source.git-config'
+
     it "can use the filePath to load the correct grammar based on the grammar's filetype", ->
       waitsForPromise ->
         atom.packages.activatePackage('language-git')

    waitsForPromise ->
      atom.packages.activatePackage('language-ruby')

  afterEach ->
    atom.packages.deactivatePackages()
    atom.packages.unloadPackages()

path = require 'path'
fs = require 'fs-plus'
temp = require 'temp'
GrammarRegistry = require '../src/grammar-registry'

describe "the `grammars` global", ->
  beforeEach ->
