Skip to content

Commit d283f65

Browse files
hakanensariclaude
andcommitted
test: add User fixture to smoke test null: false with RBS
Adds a User fixture demonstrating the null: false feature: - id: required + non-null - name: optional + non-null when present - bio: optional + nullable This fixture serves as both a test and documentation of the feature, and ensures Steep type checking works correctly with the new option. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bd4c320 commit d283f65

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

test/fixtures/usage.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require_relative "product"
66
require_relative "tag_collection"
77
require_relative "tree_node"
8+
require_relative "user"
89

910
# Test that application code using Structure classes type-checks correctly. These should all pass Steep with no
1011
# warnings.
@@ -48,3 +49,13 @@
4849
tree_node.children
4950
tree_node.children&.first&.name
5051
tree_node.children&.first&.tags
52+
53+
user = User.parse(id: "123", name: "Alice", bio: "Developer")
54+
user.id
55+
user.name
56+
user.bio
57+
58+
user_without_bio = User.parse(id: "456", name: "Bob")
59+
user_without_bio.id
60+
user_without_bio.name
61+
user_without_bio.bio

test/fixtures/user.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require "structure"
4+
5+
User = Structure.new do
6+
attribute(:id, String, null: false)
7+
attribute?(:name, String, null: false)
8+
attribute?(:bio, String)
9+
end

test/fixtures/user.rbs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class User < Data
2+
def self.new: (id: String?, ?name: String?, ?bio: String?) -> User
3+
| (String?, String?, String?) -> User
4+
def self.[]: (id: String?, ?name: String?, ?bio: String?) -> User
5+
| (String?, String?, String?) -> User
6+
7+
def self.members: () -> [ :id, :name, :bio ]
8+
9+
def self.parse: (?Hash[String | Symbol, untyped], **untyped) -> User
10+
11+
attr_reader bio: String?
12+
attr_reader id: String?
13+
attr_reader name: String?
14+
15+
def members: () -> [ :id, :name, :bio ]
16+
def to_h: () -> { id: String?, name: String?, bio: String? }
17+
end

test/test_rbs.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require_relative "fixtures/product"
1111
require_relative "fixtures/tag_collection"
1212
require_relative "fixtures/tree_node"
13+
require_relative "fixtures/user"
1314

1415
class TestRBS < Minitest::Test
1516
def setup
@@ -64,6 +65,13 @@ def test_emit_rbs_mixed_array_and_self_referential
6465
assert_equal(expected.strip, actual.strip)
6566
end
6667

68+
def test_emit_rbs_non_nullable
69+
expected = File.read("test/fixtures/user.rbs")
70+
actual = Structure::RBS.emit(User)
71+
72+
assert_equal(expected.strip, actual.strip)
73+
end
74+
6775
def test_emit_rbs_non_data_class
6876
result = Structure::RBS.emit(String)
6977

0 commit comments

Comments
 (0)