Add handling for files with no extension to special sort

Due to substring logic, files with no extension were treated as files
with no path. This change ensures that these files are properly
alphabetized in the file-list.

Also adds a behavior test to the suite.

Bug: Issue 4697
Change-Id: I41df0db4ca981919d9e435e850737115fc97b8d9
This commit is contained in:
Kasper Nilsson
2016-10-03 11:56:34 -07:00
parent 72e4e7b362
commit 6eb9a84be9
5 changed files with 53 additions and 6 deletions

View File

@@ -31,11 +31,11 @@ limitations under the License.
var aLastDotIndex = a.lastIndexOf('.');
var aExt = a.substr(aLastDotIndex + 1);
var aFile = a.substr(0, aLastDotIndex);
var aFile = a.substr(0, aLastDotIndex) || a;
var bLastDotIndex = b.lastIndexOf('.');
var bExt = b.substr(bLastDotIndex + 1);
var bFile = b.substr(0, bLastDotIndex);
var bFile = b.substr(0, bLastDotIndex) || b;
// Sort header files above others with the same base name.
var headerExts = ['h', 'hxx', 'hpp'];

View File

@@ -0,0 +1,37 @@
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="../../bower_components/web-component-tester/browser.js"></script>
<title>gr-path-list-behavior</title>
<link rel="import" href="../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-path-list-behavior.html">
<script>
suite('gr-path-list-behavior tests', function() {
test('special sort', function() {
var sort = Gerrit.PathListBehavior.specialFilePathCompare;
var testFiles = [
'/a.h',
'/a.cpp',
'/COMMIT_MSG',
'/asdasd',
'/mrPeanutbutter.py'
];
assert.deepEqual(testFiles.sort(sort),
['/COMMIT_MSG', '/a.h', '/a.cpp', '/asdasd', '/mrPeanutbutter.py']);
});
});
</script>

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../../behaviors/gr-path-list-behavior.html">
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../shared/gr-linked-text/gr-linked-text.html">

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../../behaviors/gr-path-list-behavior.html">
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<script src="../../../bower_components/es6-promise/dist/es6-promise.min.js"></script>
<script src="../../../bower_components/fetch/fetch.js"></script>

View File

@@ -22,8 +22,10 @@ limitations under the License.
<script src="../bower_components/web-component-tester/browser.js"></script>
<script>
var testFiles = [];
var basePath = '../elements/';
var elementsPath = '../elements/';
var behaviorsPath = '../behaviors/';
// Elements tests.
[
'change/gr-account-entry/gr-account-entry_test.html',
'change/gr-account-list/gr-account-list_test.html',
@@ -94,10 +96,18 @@ limitations under the License.
'shared/gr-select/gr-select_test.html',
'shared/gr-storage/gr-storage_test.html',
].forEach(function(file) {
file = basePath + file;
file = elementsPath + file;
testFiles.push(file);
testFiles.push(file + '?dom=shadow');
});
// Behaviors tests.
[
'gr-path-list-behavior/gr-path-list-behavior_test.html',
].forEach(function(file) {
file = behaviorsPath + file;
testFiles.push(file);
});
WCT.loadSuites(testFiles);
</script>