config: Move leftover input tests to input
Browse files at this commit91257862e511f87fb70f954e923617bd1eb17759Parent: 17846932 changed files +202 -203
- niri-config/src/input.rs +191 -0
- niri-config/src/lib.rs +11 -203
niri-config/src/input.rsmodified+191 -0
| @@ -448,6 +448,197 @@ mod tests { | |||
| 448 | 448 | ||
| 449 | use super::*; | 449 | use super::*; |
| 450 | 450 | ||
| 451 | + #[track_caller] | ||
| 452 | + fn do_parse(text: &str) -> Input { | ||
| 453 | + knuffel::parse("test.kdl", text) | ||
| 454 | + .map_err(miette::Report::new) | ||
| 455 | + .unwrap() | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + #[test] | ||
| 459 | + fn parse_scroll_factor_combined() { | ||
| 460 | + // Test combined scroll-factor syntax | ||
| 461 | + let parsed = do_parse( | ||
| 462 | + r#" | ||
| 463 | + mouse { | ||
| 464 | + scroll-factor 2.0 | ||
| 465 | + } | ||
| 466 | + touchpad { | ||
| 467 | + scroll-factor 1.5 | ||
| 468 | + } | ||
| 469 | + "#, | ||
| 470 | + ); | ||
| 471 | + | ||
| 472 | + assert_debug_snapshot!(parsed.mouse.scroll_factor, @r#" | ||
| 473 | + Some( | ||
| 474 | + ScrollFactor { | ||
| 475 | + base: Some( | ||
| 476 | + FloatOrInt( | ||
| 477 | + 2.0, | ||
| 478 | + ), | ||
| 479 | + ), | ||
| 480 | + horizontal: None, | ||
| 481 | + vertical: None, | ||
| 482 | + }, | ||
| 483 | + ) | ||
| 484 | + "#); | ||
| 485 | + assert_debug_snapshot!(parsed.touchpad.scroll_factor, @r#" | ||
| 486 | + Some( | ||
| 487 | + ScrollFactor { | ||
| 488 | + base: Some( | ||
| 489 | + FloatOrInt( | ||
| 490 | + 1.5, | ||
| 491 | + ), | ||
| 492 | + ), | ||
| 493 | + horizontal: None, | ||
| 494 | + vertical: None, | ||
| 495 | + }, | ||
| 496 | + ) | ||
| 497 | + "#); | ||
| 498 | + } | ||
| 499 | + | ||
| 500 | + #[test] | ||
| 501 | + fn parse_scroll_factor_split() { | ||
| 502 | + // Test split horizontal/vertical syntax | ||
| 503 | + let parsed = do_parse( | ||
| 504 | + r#" | ||
| 505 | + mouse { | ||
| 506 | + scroll-factor horizontal=2.0 vertical=-1.0 | ||
| 507 | + } | ||
| 508 | + touchpad { | ||
| 509 | + scroll-factor horizontal=-1.5 vertical=0.5 | ||
| 510 | + } | ||
| 511 | + "#, | ||
| 512 | + ); | ||
| 513 | + | ||
| 514 | + assert_debug_snapshot!(parsed.mouse.scroll_factor, @r#" | ||
| 515 | + Some( | ||
| 516 | + ScrollFactor { | ||
| 517 | + base: None, | ||
| 518 | + horizontal: Some( | ||
| 519 | + FloatOrInt( | ||
| 520 | + 2.0, | ||
| 521 | + ), | ||
| 522 | + ), | ||
| 523 | + vertical: Some( | ||
| 524 | + FloatOrInt( | ||
| 525 | + -1.0, | ||
| 526 | + ), | ||
| 527 | + ), | ||
| 528 | + }, | ||
| 529 | + ) | ||
| 530 | + "#); | ||
| 531 | + assert_debug_snapshot!(parsed.touchpad.scroll_factor, @r#" | ||
| 532 | + Some( | ||
| 533 | + ScrollFactor { | ||
| 534 | + base: None, | ||
| 535 | + horizontal: Some( | ||
| 536 | + FloatOrInt( | ||
| 537 | + -1.5, | ||
| 538 | + ), | ||
| 539 | + ), | ||
| 540 | + vertical: Some( | ||
| 541 | + FloatOrInt( | ||
| 542 | + 0.5, | ||
| 543 | + ), | ||
| 544 | + ), | ||
| 545 | + }, | ||
| 546 | + ) | ||
| 547 | + "#); | ||
| 548 | + } | ||
| 549 | + | ||
| 550 | + #[test] | ||
| 551 | + fn parse_scroll_factor_partial() { | ||
| 552 | + // Test partial specification (only one axis) | ||
| 553 | + let parsed = do_parse( | ||
| 554 | + r#" | ||
| 555 | + mouse { | ||
| 556 | + scroll-factor horizontal=2.0 | ||
| 557 | + } | ||
| 558 | + touchpad { | ||
| 559 | + scroll-factor vertical=-1.5 | ||
| 560 | + } | ||
| 561 | + "#, | ||
| 562 | + ); | ||
| 563 | + | ||
| 564 | + assert_debug_snapshot!(parsed.mouse.scroll_factor, @r#" | ||
| 565 | + Some( | ||
| 566 | + ScrollFactor { | ||
| 567 | + base: None, | ||
| 568 | + horizontal: Some( | ||
| 569 | + FloatOrInt( | ||
| 570 | + 2.0, | ||
| 571 | + ), | ||
| 572 | + ), | ||
| 573 | + vertical: None, | ||
| 574 | + }, | ||
| 575 | + ) | ||
| 576 | + "#); | ||
| 577 | + assert_debug_snapshot!(parsed.touchpad.scroll_factor, @r#" | ||
| 578 | + Some( | ||
| 579 | + ScrollFactor { | ||
| 580 | + base: None, | ||
| 581 | + horizontal: None, | ||
| 582 | + vertical: Some( | ||
| 583 | + FloatOrInt( | ||
| 584 | + -1.5, | ||
| 585 | + ), | ||
| 586 | + ), | ||
| 587 | + }, | ||
| 588 | + ) | ||
| 589 | + "#); | ||
| 590 | + } | ||
| 591 | + | ||
| 592 | + #[test] | ||
| 593 | + fn parse_scroll_factor_mixed() { | ||
| 594 | + // Test mixed base + override syntax | ||
| 595 | + let parsed = do_parse( | ||
| 596 | + r#" | ||
| 597 | + mouse { | ||
| 598 | + scroll-factor 2 vertical=-1 | ||
| 599 | + } | ||
| 600 | + touchpad { | ||
| 601 | + scroll-factor 1.5 horizontal=3 | ||
| 602 | + } | ||
| 603 | + "#, | ||
| 604 | + ); | ||
| 605 | + | ||
| 606 | + assert_debug_snapshot!(parsed.mouse.scroll_factor, @r#" | ||
| 607 | + Some( | ||
| 608 | + ScrollFactor { | ||
| 609 | + base: Some( | ||
| 610 | + FloatOrInt( | ||
| 611 | + 2.0, | ||
| 612 | + ), | ||
| 613 | + ), | ||
| 614 | + horizontal: None, | ||
| 615 | + vertical: Some( | ||
| 616 | + FloatOrInt( | ||
| 617 | + -1.0, | ||
| 618 | + ), | ||
| 619 | + ), | ||
| 620 | + }, | ||
| 621 | + ) | ||
| 622 | + "#); | ||
| 623 | + assert_debug_snapshot!(parsed.touchpad.scroll_factor, @r#" | ||
| 624 | + Some( | ||
| 625 | + ScrollFactor { | ||
| 626 | + base: Some( | ||
| 627 | + FloatOrInt( | ||
| 628 | + 1.5, | ||
| 629 | + ), | ||
| 630 | + ), | ||
| 631 | + horizontal: Some( | ||
| 632 | + FloatOrInt( | ||
| 633 | + 3.0, | ||
| 634 | + ), | ||
| 635 | + ), | ||
| 636 | + vertical: None, | ||
| 637 | + }, | ||
| 638 | + ) | ||
| 639 | + "#); | ||
| 640 | + } | ||
| 641 | + | ||
| 451 | #[test] | 642 | #[test] |
| 452 | fn scroll_factor_h_v_factors() { | 643 | fn scroll_factor_h_v_factors() { |
| 453 | let sf = ScrollFactor { | 644 | let sf = ScrollFactor { |
niri-config/src/lib.rsmodified+11 -203
| @@ -239,203 +239,23 @@ mod tests { | |||
| 239 | 239 | ||
| 240 | use super::*; | 240 | use super::*; |
| 241 | 241 | ||
| 242 | - #[track_caller] | ||
| 243 | - fn do_parse(text: &str) -> Config { | ||
| 244 | - Config::parse("test.kdl", text) | ||
| 245 | - .map_err(miette::Report::new) | ||
| 246 | - .unwrap() | ||
| 247 | - } | ||
| 248 | - | ||
| 249 | #[test] | 242 | #[test] |
| 250 | - fn parse_scroll_factor_combined() { | 243 | + fn can_create_default_config() { |
| 251 | - // Test combined scroll-factor syntax | 244 | + let _ = Config::default(); |
| 252 | - let parsed = do_parse( | ||
| 253 | - r#" | ||
| 254 | - input { | ||
| 255 | - mouse { | ||
| 256 | - scroll-factor 2.0 | ||
| 257 | - } | ||
| 258 | - touchpad { | ||
| 259 | - scroll-factor 1.5 | ||
| 260 | - } | ||
| 261 | - } | ||
| 262 | - "#, | ||
| 263 | - ); | ||
| 264 | - | ||
| 265 | - assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#" | ||
| 266 | - Some( | ||
| 267 | - ScrollFactor { | ||
| 268 | - base: Some( | ||
| 269 | - FloatOrInt( | ||
| 270 | - 2.0, | ||
| 271 | - ), | ||
| 272 | - ), | ||
| 273 | - horizontal: None, | ||
| 274 | - vertical: None, | ||
| 275 | - }, | ||
| 276 | - ) | ||
| 277 | - "#); | ||
| 278 | - assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#" | ||
| 279 | - Some( | ||
| 280 | - ScrollFactor { | ||
| 281 | - base: Some( | ||
| 282 | - FloatOrInt( | ||
| 283 | - 1.5, | ||
| 284 | - ), | ||
| 285 | - ), | ||
| 286 | - horizontal: None, | ||
| 287 | - vertical: None, | ||
| 288 | - }, | ||
| 289 | - ) | ||
| 290 | - "#); | ||
| 291 | - } | ||
| 292 | - | ||
| 293 | - #[test] | ||
| 294 | - fn parse_scroll_factor_split() { | ||
| 295 | - // Test split horizontal/vertical syntax | ||
| 296 | - let parsed = do_parse( | ||
| 297 | - r#" | ||
| 298 | - input { | ||
| 299 | - mouse { | ||
| 300 | - scroll-factor horizontal=2.0 vertical=-1.0 | ||
| 301 | - } | ||
| 302 | - touchpad { | ||
| 303 | - scroll-factor horizontal=-1.5 vertical=0.5 | ||
| 304 | - } | ||
| 305 | - } | ||
| 306 | - "#, | ||
| 307 | - ); | ||
| 308 | - | ||
| 309 | - assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#" | ||
| 310 | - Some( | ||
| 311 | - ScrollFactor { | ||
| 312 | - base: None, | ||
| 313 | - horizontal: Some( | ||
| 314 | - FloatOrInt( | ||
| 315 | - 2.0, | ||
| 316 | - ), | ||
| 317 | - ), | ||
| 318 | - vertical: Some( | ||
| 319 | - FloatOrInt( | ||
| 320 | - -1.0, | ||
| 321 | - ), | ||
| 322 | - ), | ||
| 323 | - }, | ||
| 324 | - ) | ||
| 325 | - "#); | ||
| 326 | - assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#" | ||
| 327 | - Some( | ||
| 328 | - ScrollFactor { | ||
| 329 | - base: None, | ||
| 330 | - horizontal: Some( | ||
| 331 | - FloatOrInt( | ||
| 332 | - -1.5, | ||
| 333 | - ), | ||
| 334 | - ), | ||
| 335 | - vertical: Some( | ||
| 336 | - FloatOrInt( | ||
| 337 | - 0.5, | ||
| 338 | - ), | ||
| 339 | - ), | ||
| 340 | - }, | ||
| 341 | - ) | ||
| 342 | - "#); | ||
| 343 | } | 245 | } |
| 344 | 246 | ||
| 345 | #[test] | 247 | #[test] |
| 346 | - fn parse_scroll_factor_partial() { | 248 | + fn default_repeat_params() { |
| 347 | - // Test partial specification (only one axis) | 249 | + let config = Config::parse("config.kdl", "").unwrap(); |
| 348 | - let parsed = do_parse( | 250 | + assert_eq!(config.input.keyboard.repeat_delay, 600); |
| 349 | - r#" | 251 | + assert_eq!(config.input.keyboard.repeat_rate, 25); |
| 350 | - input { | ||
| 351 | - mouse { | ||
| 352 | - scroll-factor horizontal=2.0 | ||
| 353 | - } | ||
| 354 | - touchpad { | ||
| 355 | - scroll-factor vertical=-1.5 | ||
| 356 | - } | ||
| 357 | - } | ||
| 358 | - "#, | ||
| 359 | - ); | ||
| 360 | - | ||
| 361 | - assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#" | ||
| 362 | - Some( | ||
| 363 | - ScrollFactor { | ||
| 364 | - base: None, | ||
| 365 | - horizontal: Some( | ||
| 366 | - FloatOrInt( | ||
| 367 | - 2.0, | ||
| 368 | - ), | ||
| 369 | - ), | ||
| 370 | - vertical: None, | ||
| 371 | - }, | ||
| 372 | - ) | ||
| 373 | - "#); | ||
| 374 | - assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#" | ||
| 375 | - Some( | ||
| 376 | - ScrollFactor { | ||
| 377 | - base: None, | ||
| 378 | - horizontal: None, | ||
| 379 | - vertical: Some( | ||
| 380 | - FloatOrInt( | ||
| 381 | - -1.5, | ||
| 382 | - ), | ||
| 383 | - ), | ||
| 384 | - }, | ||
| 385 | - ) | ||
| 386 | - "#); | ||
| 387 | } | 252 | } |
| 388 | 253 | ||
| 389 | - #[test] | 254 | + #[track_caller] |
| 390 | - fn parse_scroll_factor_mixed() { | 255 | + fn do_parse(text: &str) -> Config { |
| 391 | - // Test mixed base + override syntax | 256 | + Config::parse("test.kdl", text) |
| 392 | - let parsed = do_parse( | 257 | + .map_err(miette::Report::new) |
| 393 | - r#" | 258 | + .unwrap() |
| 394 | - input { | ||
| 395 | - mouse { | ||
| 396 | - scroll-factor 2 vertical=-1 | ||
| 397 | - } | ||
| 398 | - touchpad { | ||
| 399 | - scroll-factor 1.5 horizontal=3 | ||
| 400 | - } | ||
| 401 | - } | ||
| 402 | - "#, | ||
| 403 | - ); | ||
| 404 | - | ||
| 405 | - assert_debug_snapshot!(parsed.input.mouse.scroll_factor, @r#" | ||
| 406 | - Some( | ||
| 407 | - ScrollFactor { | ||
| 408 | - base: Some( | ||
| 409 | - FloatOrInt( | ||
| 410 | - 2.0, | ||
| 411 | - ), | ||
| 412 | - ), | ||
| 413 | - horizontal: None, | ||
| 414 | - vertical: Some( | ||
| 415 | - FloatOrInt( | ||
| 416 | - -1.0, | ||
| 417 | - ), | ||
| 418 | - ), | ||
| 419 | - }, | ||
| 420 | - ) | ||
| 421 | - "#); | ||
| 422 | - assert_debug_snapshot!(parsed.input.touchpad.scroll_factor, @r#" | ||
| 423 | - Some( | ||
| 424 | - ScrollFactor { | ||
| 425 | - base: Some( | ||
| 426 | - FloatOrInt( | ||
| 427 | - 1.5, | ||
| 428 | - ), | ||
| 429 | - ), | ||
| 430 | - horizontal: Some( | ||
| 431 | - FloatOrInt( | ||
| 432 | - 3.0, | ||
| 433 | - ), | ||
| 434 | - ), | ||
| 435 | - vertical: None, | ||
| 436 | - }, | ||
| 437 | - ) | ||
| 438 | - "#); | ||
| 439 | } | 259 | } |
| 440 | 260 | ||
| 441 | #[test] | 261 | #[test] |
| @@ -1924,16 +1744,4 @@ mod tests { | |||
| 1924 | } | 1744 | } |
| 1925 | "#); | 1745 | "#); |
| 1926 | } | 1746 | } |
| 1927 | - | ||
| 1928 | - #[test] | ||
| 1929 | - fn can_create_default_config() { | ||
| 1930 | - let _ = Config::default(); | ||
| 1931 | - } | ||
| 1932 | - | ||
| 1933 | - #[test] | ||
| 1934 | - fn default_repeat_params() { | ||
| 1935 | - let config = Config::parse("config.kdl", "").unwrap(); | ||
| 1936 | - assert_eq!(config.input.keyboard.repeat_delay, 600); | ||
| 1937 | - assert_eq!(config.input.keyboard.repeat_rate, 25); | ||
| 1938 | - } | ||
| 1939 | } | 1747 | } |