Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift `build` & `test`

permissions:
contents: read

on:
push:
branches: [ "main" ]
paths-ignore:
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'

jobs:
build-and-test:
runs-on: macos-latest
timeout-minutes: 20

steps:
- name: Checkout
uses: actions/checkout@v5

- name: Show Swift version
run: swift --version

- name: Cache SwiftPM dependencies
uses: actions/cache@v4
with:
path: .build
key: ${{ runner.os }}-swiftpm-${{ hashFiles('Package.resolved') }}
restore-keys: |
${{ runner.os }}-swiftpm-

- name: Build
run: swift build --configuration debug

- name: Run tests
run: swift test --configuration debug --parallel --verbose
11 changes: 11 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"default": true,
"MD012": false,
"MD013": false,
"MD024": {
"siblings_only": true
},
"MD033": false,
"MD041": false,
"MD060": false
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### πŸ› Fixes

* fixed optional types not detected with `valueCoder` strategy ([#141](https://github.com/SwiftyLab/MetaCodable/issues/141)) ([5873c3e](https://github.com/SwiftyLab/MetaCodable/commit/5873c3e33ab98e61c06304bfc2a2c93ab199d65d))
* removed unreachable `default` case warnings for `Bool` type switches in macro-generated code

## [1.5.0](https://github.com/SwiftyLab/MetaCodable/compare/v1.4.0...v1.5.0) (2025-07-08)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# MetaCodable

[![Swift `build` & `test`](https://github.com/qizh/MetaCodable/actions/workflows/swift.yml/badge.svg?branch=tests%2Fimprove%2Fcoverage%2F30-01-26)](https://github.com/qizh/MetaCodable/actions/workflows/swift.yml)
[![API Docs](http://img.shields.io/badge/Read_the-docs-2196f3.svg)](https://swiftpackageindex.com/SwiftyLab/MetaCodable/documentation/metacodable)
[![Swift Package Manager Compatible](https://img.shields.io/github/v/tag/SwiftyLab/MetaCodable?label=SPM&color=orange)](https://badge.fury.io/gh/SwiftyLab%2FMetaCodable)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/MetaCodable.svg?label=CocoaPods&color=C90005)](https://badge.fury.io/co/MetaCodable)
Expand Down
19 changes: 12 additions & 7 deletions Tests/MetaCodableTests/AccessModifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import Testing

@testable import PluginCore

@Suite("Access Modifier Tests")
struct AccessModifierTests {
@Suite("Access Modifier - Open")
struct Open {
@Codable
open class SomeCodable {
let value: String
}

@Test
@Test("Generates @Codable conformance for class with 'open' access", .tags(.accessModifiers, .classes, .codable, .decoding, .encoding, .enums, .macroExpansion))
func expansion() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -49,7 +51,7 @@ struct AccessModifierTests {
)
}

@Test
@Test("Decodes class from JSON successfully", .tags(.accessModifiers, .classes, .decoding))
func openClassDecodingOnly() throws {
// Open class doesn't have memberwise init, only decoder init
let jsonStr = """
Expand All @@ -63,7 +65,7 @@ struct AccessModifierTests {
#expect(decoded.value == "open_test")
}

@Test
@Test("Decodes from JSON successfully", .tags(.accessModifiers, .decoding))
func openClassFromJSON() throws {
let jsonStr = """
{
Expand All @@ -77,14 +79,15 @@ struct AccessModifierTests {
}
}

@Suite("Access Modifier - Public")
struct Public {
@Codable
@MemberInit
public struct SomeCodable {
let value: String
}

@Test
@Test("Generates macro expansion with @Codable for struct with 'public' access", .tags(.accessModifiers, .codable, .decoding, .encoding, .enums, .macroExpansion, .memberInit, .structs))
func expansion() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -127,7 +130,7 @@ struct AccessModifierTests {
)
}

@Test
@Test("Encodes and decodes successfully", .tags(.accessModifiers, .decoding, .encoding))
func publicStructDecodingAndEncoding() throws {
let original = SomeCodable(value: "public_test")
let encoded = try JSONEncoder().encode(original)
Expand All @@ -136,7 +139,7 @@ struct AccessModifierTests {
#expect(decoded.value == "public_test")
}

@Test
@Test("Decodes from JSON successfully (AccessModifierTests #1)", .tags(.accessModifiers, .decoding))
func publicStructFromJSON() throws {
let jsonStr = """
{
Expand All @@ -150,14 +153,15 @@ struct AccessModifierTests {
}
}

@Suite("Access Modifier - Package")
struct Package {
@Codable
@MemberInit
package struct SomeCodable {
let value: String
}

@Test
@Test("Generates macro expansion with @Codable for struct", .tags(.accessModifiers, .codable, .decoding, .encoding, .enums, .macroExpansion, .memberInit, .structs))
func expansion() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -201,6 +205,7 @@ struct AccessModifierTests {
}
}

@Suite("Access Modifier - Others")
struct Others {
struct Internal {
@Codable
Expand Down
7 changes: 4 additions & 3 deletions Tests/MetaCodableTests/Attributes/CodedByTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import Testing

@testable import PluginCore

@Suite("Coded By Tests")
struct CodedByTests {
@Test
@Test("Reports error for @CodedBy misuse", .tags(.codedBy, .errorHandling, .macroExpansion, .structs))
func misuseOnNonVariableDeclaration() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -34,7 +35,7 @@ struct CodedByTests {
)
}

@Test
@Test("Reports error for @CodedBy misuse (CodedByTests #1)", .tags(.codedBy, .errorHandling, .macroExpansion, .structs))
func misuseOnStaticVariable() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -63,7 +64,7 @@ struct CodedByTests {
)
}

@Test
@Test("Reports error when @CodedBy is applied multiple times", .tags(.codedBy, .errorHandling, .macroExpansion, .structs))
func duplicatedMisuse() throws {
assertMacroExpansion(
"""
Expand Down
14 changes: 8 additions & 6 deletions Tests/MetaCodableTests/Attributes/DefaultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Testing

@testable import PluginCore

@Suite("Default Tests")
struct DefaultTests {
@Test
@Test("Reports error for @Default misuse", .tags(.default, .errorHandling, .macroExpansion, .structs))
func misuseOnNonVariableDeclaration() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -36,7 +37,7 @@ struct DefaultTests {
)
}

@Test
@Test("Reports error for @Default misuse (DefaultTests #1)", .tags(.default, .errorHandling, .macroExpansion, .structs))
func misuseOnStaticVariable() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -65,7 +66,7 @@ struct DefaultTests {
)
}

@Test
@Test("Reports error when @Default is applied multiple times", .tags(.default, .errorHandling, .macroExpansion, .structs))
func duplicatedMisuse() throws {
assertMacroExpansion(
"""
Expand Down Expand Up @@ -104,6 +105,7 @@ struct DefaultTests {
)
}

@Suite("Default - Default Value Behavior")
struct DefaultValueBehavior {
@Codable
struct SomeCodable {
Expand All @@ -113,7 +115,7 @@ struct DefaultTests {
let number: Int
}

@Test
@Test("Decodes from JSON successfully (DefaultTests #2)", .tags(.decoding, .default))
func defaultValueUsage() throws {
// Test with missing keys in JSON
let jsonStr = "{}"
Expand All @@ -124,7 +126,7 @@ struct DefaultTests {
#expect(decoded.number == 42)
}

@Test
@Test("Decodes from JSON successfully (DefaultTests #3)", .tags(.decoding, .default))
func overrideDefaultValues() throws {
// Test with provided values in JSON
let jsonStr = """
Expand All @@ -140,7 +142,7 @@ struct DefaultTests {
#expect(decoded.number == 100)
}

@Test
@Test("Encodes and decodes successfully (DefaultTests #1)", .tags(.decoding, .default, .encoding))
func encodingWithDefaults() throws {
let original = SomeCodable(value: "test", number: 99)
let encoded = try JSONEncoder().encode(original)
Expand Down
Loading