Skip to content

Added count function - #1831

Merged
olavsorl merged 4 commits into
mainfrom
feature/1830-add-list-count-expression
Jul 6, 2026
Merged

Added count function#1831
olavsorl merged 4 commits into
mainfrom
feature/1830-add-list-count-expression

Conversation

@olavsorl

@olavsorl olavsorl commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

Added count expression function

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • New Features

    • Added an expression function to count the number of elements in a list (JSON arrays), including support for empty lists and lists containing nulls.
    • Handles nested lists as single elements (no flattening).
  • Bug Fixes

    • Improved validation: provides clear errors when count is called with an invalid argument count or when the argument is not a list.
  • Tests

    • Added shared test cases and coverage for both valid and failing count scenarios.

@olavsorl olavsorl linked an issue Jun 25, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7c648aab-7e50-4eff-b705-cef18708b373

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1ad75 and 9f9b8e0.

📒 Files selected for processing (1)
  • test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt

📝 Walkthrough

Walkthrough

Adds count to the expression function enum, routes evaluation to a new count helper, records the API snapshot change, and adds shared tests for valid list counts plus invalid arity and type cases.

Changes

List count expression

Layer / File(s) Summary
Expression function and evaluator dispatch
src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs, src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs, test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
ExpressionFunction gains count, EvaluateExpression_internal dispatches to a new helper that accepts one JSON array and returns its element count, and the public API snapshot records the new enum member.
Shared count test coverage
test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs, test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/count/count.json
Adds the count shared-test entry point and cases for successful list counts plus invalid arity and non-list inputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a count function.
Linked Issues check ✅ Passed The changes implement the requested list count expression and return the number of elements in a list.
Out of Scope Changes check ✅ Passed The added tests and public API snapshot update are directly related to the new count function and not out of scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/1830-add-list-count-expression

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@olavsorl olavsorl added feature Label Pull requests with new features. Used when generation releasenotes backport-ignore This PR is a new feature and should not be cherry-picked onto release branches labels Jun 25, 2026
@TomasEng

Copy link
Copy Markdown
Contributor

Det ser ut til at det er en test som feiler her.

@olavsorl
olavsorl enabled auto-merge (squash) July 6, 2026 11:40
@olavsorl
olavsorl merged commit 40aa9bd into main Jul 6, 2026
11 checks passed
@olavsorl
olavsorl deleted the feature/1830-add-list-count-expression branch July 6, 2026 11:46
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches feature Label Pull requests with new features. Used when generation releasenotes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add list count expression

2 participants