---
policy: /ce/unit-test/size/collection
logic: /ce/unit-test/size/collection/unit-test.logic.yaml
executionTime: 2026-01-12T19:27:56.287828139Z
generationMs: 80
executionMs: 1148
rows:
  - id: Test-1
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: "unitTest(Test-1): null.size() == number(0.0)"
      actual: "unitTest(Test-1): null.size() == number(0.0)"
    runtimeError: {}
  - id: Test-2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: "unitTest(Test-2): setOfText([]).size() == number(0.0)"
      actual: "unitTest(Test-2): setOfText([]).size() == number(0.0)"
    runtimeError: {}
  - id: Test-3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: "unitTest(Test-3): setOfText(['a', 'b', 'c']).size() == number(3.0)"
      actual: "unitTest(Test-3): setOfText(['a', 'b', 'c']).size() == number(3.0)"
    runtimeError: {}
  - id: Test-4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: "unitTest(Test-4): setOfText(['a', 'a', 'a']).size() == number(1.0)"
      actual: "unitTest(Test-4): setOfText(['a', 'a', 'a']).size() == number(1.0)"
    runtimeError: {}
  - id: Test-5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: "unitTest(Test-5): setOfText(['a', 'A', ' A ', '\\ta\\n\\r']).size()\
        \ == number(1.0)"
      actual: "unitTest(Test-5): setOfText(['a', 'A', ' A ', '\\ta\\n\\r']).size()\
        \ == number(1.0)"
    runtimeError: {}
usedFiles:
  - path: /ce/unit-test/size/collection/policy.yaml
    md5Hash: BFC4637B0FD9AF567078D0716D30FC17
    content: |
      ---
      names:
        full: "SIZE Unit Tests: CollectionType"
        contextual: CollectionType
      description: "Unit tests for SIZE operation: CollectionType"
  - path: /ce/unit-test/size/collection/unit-test.logic.yaml
    md5Hash: 47672DC03CF280DA50A4B840F9E2E240
    content: |-
      ---
      inputType: CA10__CaAwsInstance__c
      conditions:
        - status: COMPLIANT
          currentStateMessage: Test-1
          check:
            UNIT_TEST:
              id: Test-1
              expected:
                 text: "unitTest(Test-1): null.size() == number(0.0)"
              arg:
                IS_EQUAL:
                  left:
                    SIZE:
                      arg:
                        UNIT_TEST_NULL:
                          returnType: SET_OF_TEXT
                  right:
                    NUMBER: 0
        - status: COMPLIANT
          currentStateMessage: Test-2
          check:
            UNIT_TEST:
              id: Test-2
              expected:
                text: "unitTest(Test-2): setOfText([]).size() == number(0.0)"
              arg:
                IS_EQUAL:
                  left:
                    SIZE:
                      arg:
                        SET:
                          itemType: TEXT
                          items: []
                  right:
                    NUMBER: 0
        - status: COMPLIANT
          currentStateMessage: Test-3
          check:
            UNIT_TEST:
              id: Test-3
              expected:
                text: "unitTest(Test-3): setOfText(['a', 'b', 'c']).size() == number(3.0)"
              arg:
                IS_EQUAL:
                  left:
                    SIZE:
                      arg:
                        SET:
                          itemType: TEXT
                          items:
                            - a
                            - b
                            - c
                  right:
                    NUMBER: 3
        - status: COMPLIANT
          currentStateMessage: Test-4
          check:
            UNIT_TEST:
              id: Test-4
              expected:
                text: "unitTest(Test-4): setOfText(['a', 'a', 'a']).size() == number(1.0)"
              arg:
                IS_EQUAL:
                  left:
                    SIZE:
                      arg:
                        SET:
                          itemType: TEXT
                          items:
                            - a
                            - a
                            - a
                  right:
                    NUMBER: 1
        - status: COMPLIANT
          currentStateMessage: Test-5
          check:
            UNIT_TEST:
              id: Test-5
              expected:
                text: "unitTest(Test-5): setOfText(['a', 'A', ' A ', '\\ta\\n\\r']).size() == number(1.0)"
              arg:
                IS_EQUAL:
                  left:
                    SIZE:
                      arg:
                        SET:
                          itemType: TEXT
                          items:
                            - "a"
                            - "A"
                            - " A "
                            - "\ta\n\r"
                  right:
                    NUMBER: 1
      otherwise:
        status: INCOMPLIANT
        currentStateMessage: Test Failed
        remediationMessage: Developer Fix Required
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "Test-1",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : 199,
      "conditionText" : "unitTest(Test-1): null.size() == number(0.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "Test-2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : 299,
      "conditionText" : "unitTest(Test-2): setOfText([]).size() == number(0.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "Test-3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : 399,
      "conditionText" : "unitTest(Test-3): setOfText(['a', 'b', 'c']).size() == number(3.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "Test-4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : 499,
      "conditionText" : "unitTest(Test-4): setOfText(['a', 'a', 'a']).size() == number(1.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "Test-5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : 599,
      "conditionText" : "unitTest(Test-5): setOfText(['a', 'A', ' A ', '\\ta\\n\\r']).size() == number(1.0)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsInstance__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00.000Z")
    },
    "Id" : "Test-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00.000Z")
    },
    "Id" : "Test-2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00.000Z")
    },
    "Id" : "Test-3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00.000Z")
    },
    "Id" : "Test-4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-01-01T00:00:00.000Z")
    },
    "Id" : "Test-5"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsInstance__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var BytesLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg;
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
  var CollectionLib = new function () {
      this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) {
          if (arg == null) return [];
          let parts = arg.split(separator);
          return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize);
      };
      this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) {
          if (arr == null) return [];
          let result = [];
          let seen = new Set();
          arr.forEach(el => {
              let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el);
              if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) {
                  if (!skipDuplicates || !seen.has(normalized)) {
                      if (skipDuplicates) seen.add(normalized);
                      result.push(normalized);
                  }
              }
          });
          if (sort) result.sort();
          return result;
      };
      this.equal = function(left, right) {
          left = left == null ? [] : left;
          right = right == null ? [] : right;
          if (left.length !== right.length) return false;
          for (let i = 0; i < left.length; i++) {
              if (left[i] !== right[i]) return false;
          }
          return true;
      };
      this.notEqual = function(left, right) {
          return !this.equal(left, right);
      };
      this.size = function(collection) {
          return collection == null ? 0 : collection.length;
      };
      this.startsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[0] === normalizedSearch;
      };
      this.endsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[collection.length - 1] === normalizedSearch;
      };
      this.contains = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search));
      };
      this.containsAll = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
      this.containsAny = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
  }();
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      if (obj.Id == 'Test-1' && CollectionLib.size(null) == 0.0) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "unitTest(Test-1): null.size() == number(0.0)", currentStateMessage: "Test-1", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      if (obj.Id == 'Test-2' && CollectionLib.size(CollectionLib.fromArray([], true, true, true, true)) == 0.0) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "unitTest(Test-2): setOfText([]).size() == number(0.0)", currentStateMessage: "Test-2", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      if (obj.Id == 'Test-3' && CollectionLib.size(CollectionLib.fromArray(['a', 'b', 'c'], true, true, true, true)) == 3.0) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "unitTest(Test-3): setOfText(['a', 'b', 'c']).size() == number(3.0)", currentStateMessage: "Test-3", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      if (obj.Id == 'Test-4' && CollectionLib.size(CollectionLib.fromArray(['a', 'a', 'a'], true, true, true, true)) == 1.0) {
          return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "unitTest(Test-4): setOfText(['a', 'a', 'a']).size() == number(1.0)", currentStateMessage: "Test-4", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[5], conditionIndex:[500..599]
      if (obj.Id == 'Test-5' && CollectionLib.size(CollectionLib.fromArray(['a', 'A', ' A ', '\ta\n\r'], true, true, true, true)) == 1.0) {
          return {status: 'COMPLIANT', conditionIndex: 599, conditionText: "unitTest(Test-5): setOfText(['a', 'A', ' A ', '\\ta\\n\\r']).size() == number(1.0)", currentStateMessage: "Test-5", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 600, conditionText: "otherwise", currentStateMessage: "Test Failed", currentStateReferences: references1.join('\n'), remediation: "Developer Fix Required", runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.Id AS Id,
          process_CA10__CaAwsInstance__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsInstance__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
