Uploaded image for project: 'Lucee Development'
  1. LDEV-1298

built-in functions should work as sort comparators

    Details

    • Type: Incompatibility
    • Status: Backlog
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.1.4.18
    • Fix Version/s: None
    • Labels:
      None
    • Sprint:

      Description

      See http://blog.adamcameron.me/2017/04/cfml-lucee-13-v-4-14-v-6-coldfusion-we.html

      See this test case:

      component extends="testbox.system.BaseSpec" {
      	function run() {
      		describe("Other sort tests", function(){
      			it("is a baseline showing using BIFs as a callback", function(){
      				var testString = "AbCd";
      				var applyTo = function(object, operation){
      					return operation(object);
      				};
      
      				var result = applyTo(testString, ucase);
      				
      				expect(result).toBeWithCase("ABCD");
      			});
      			describe("using arrays", function(){
      				it("can use a function expression calling compareNoCase as a string comparator when sorting", function(){
      					var arrayToSort = ["d","C","b","A"];
      					
      					arrayToSort.sort(function(e1,e2){
      						return compareNoCase(e1, e2);
      					});
      					
      					expect(arrayToSort).toBe(["A","b","C","d"]);
      				});
      				it("can use the compareNoCase BIF as a string comparator when sorting", function(){
      					var arrayToSort = ["d","C","b","A"];
      					
      					arrayToSort.sort(compareNoCase);
      					
      					expect(arrayToSort).toBe(["A","b","C","d"]);
      				});
      			});
      			describe("using lists", function(){
      				it("can use a function expression calling compareNoCase as a string comparator when sorting", function(){
      					var listToSort = "d,C,b,A";
      					
      					var sortedList = listToSort.listSort(function(e1,e2){
      						return compareNoCase(e1, e2);
      					});
      					
      					expect(sortedList).toBe("A,b,C,d");
      					expect(listToSort).toBe("d,C,b,A");
      				});
      				it("can use the compareNoCase BIF as a string comparator when sorting", function(){
      					var listToSort = "d,C,b,A";
      					
      					var sortedList = listToSort.listSort(compareNoCase);
      					
      					expect(sortedList).toBe("A,b,C,d");
      					expect(listToSort).toBe("d,C,b,A");
      				});
      			});
      		});
      	}
      }
      

      Specifically:

      arrayToSort.sort(compareNoCase);
      

      And:

      var sortedList = listToSort.listSort(compareNoCase);
      

        Attachments

          Activity

            People

            • Assignee:
              michaeloffner Michael Offner
              Reporter:
              da_cameron Adam Cameron
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: